Inserting a new foreign key
If you insert a row in a dependent table, it might generate an error if there is no row in the parent table with a corresponding primary key value. Db2® prevents the insertion of the foreign key value until a primary key is created in the parent table.
The parent table can be the same as the table currently being edited
(a self-referencing constraint.
This is indicated by the absence of an R
in the rightmost position
of the prefix area for the row in error. You can use the E prefix
command to display an information panel with details of the relationship
name, the parent and dependent table names, and the names of the columns
in the key in both the parent and dependent tables.
In the situation where the parent and dependent tables are different:
- Start a File Manager/Db2 Edit session for the parent table by either using the RE prefix command, or REDIT primary command from the error information panel.
- Use the IP prefix command to insert a new row in the table, with a primary key that matches the foreign key value entered in the Edit session for the dependent table. You can also change an existing row so that its primary key matches the foreign key entered in the Edit session of the dependent table.
- Press the Exit function key (F3) to validate and commit your changes.
- Return to the original Edit session and save the new foreign key value.
Related tasks
Related references