Update rules
The update rules for referential integrity apply to parent and dependent tables.
The following update rules for referential integrity apply to parent and dependent tables:
- Parent table rules
- You cannot change a parent key column of a row that has a dependent row. If you do, the dependent row no longer satisfies the referential constraint, so Db2 prohibits the operation.
- Dependent table rules
- You cannot change the value of a foreign key column in a dependent table unless the new value exists in the parent key of the parent table.
Example
When an employee transfers from one department to another, the department number for that employee must change. The new value must be the number of an existing department, or it must be null. You should not be able to assign an employee to a department that does not exist. However, in the event of a company reorganization, employees might temporarily not report to a valid department. In this case, a null value is a possibility.
If an update to a table with a referential constraint fails, Db2 rolls back all changes that were made during the update.