Delete rules
Delete rules, which are applied to parent and dependent tables, are an important part of Db2 referential integrity.
The following delete rules for referential integrity apply to parent and dependent tables:
- For parent tables
- For any particular relationship, Db2 enforces delete rules that are based on the choices that you specify when you define the referential constraint.
- For dependent tables
- At any time, you can delete rows from a dependent table without acting on the parent table.
To delete a row from a table that has a parent key and dependent tables, you must obey the delete rules for that table. To succeed, the DELETE must satisfy all delete rules of all affected relationships. The DELETE fails if it violates any referential constraint.
Examples
- Example 1
- Consider the parent table in the department-employee relationship. Suppose that you delete the row for department C01 from the DEPT table. That deletion affects the information in the EMP table about Sally Kwan, Heather Nicholls, and Kim Natz, who work in department C01.
- Example 2
- Consider the dependent in the department-employee relationship. Assume that an employee retires and that a program deletes the row for that employee from the EMP table. The DEPT table is not affected.