Deleting a primary key

If you delete a row in a parent table, it might generate an error if there are rows in the dependent table and the delete restrict rule is specified for the relationship. The delete restrict rule prevents the deletion of the primary key value unless you first delete (or change) all the rows in the dependent table with foreign key values matching the primary key value.

In this situation:

  1. Start a File Manager/Db2 Edit session for the dependent table by either using the RE prefix command, or REDIT primary command from the error information panel. Usually, only those rows that would be affected by the deletion of the primary key in the parent table are displayed (see following note).
  2. Either delete the displayed rows (see following note), or change the values of the foreign keys to another valid value.
  3. Press the Exit function key (F3) to validate and commit your changes.
  4. Return to the Edit session for the primary table and proceed with deletion of the primary key value.
Note:
  1. In most cases, FM/Db2 shows only those rows that would be affected by the deletion of the primary key in the parent table. The exception is the situation where the parent table has a self-referencing constraint that might cause the deletion of other rows in the parent table if a primary or parent key value is deleted or changed. In this situation, FM/Db2 shows all rows and you must select the dependent rows.
  2. If the parent or dependent tables are also parent or dependent tables in other relationships, changes to the primary or foreign key values can result in other errors.

Related references