SQLCODE -532 — delete restricted by a relationship
Db2 refused to delete a parent row because rows in another table still point at it and the foreign key's delete rule does not allow it.
What happened
A DELETE (or a program's delete) failed. Nothing was deleted: Db2 undoes the whole statement.
DSNT408I SQLCODE = -532, ERROR: THE RELATIONSHIP ACCTCUST RESTRICTS THE
DELETION OF ROW WITH RID X'000000020D'
DSNT418I SQLSTATE = 23504 SQLSTATE RETURN CODEWhat it means
The table you are deleting from is the parent in a referential constraint (a foreign key). At least one child row in another table still has the parent's key, and the constraint's delete rule is RESTRICT or NO ACTION, so Db2 will not leave those children pointing at nothing. The message names the relationship, which tells you which child table to look in.
A CASCADE or SET NULL rule on this relationship does not give -532 by itself, but a cascading delete that reaches a table further down whose rule is RESTRICT or NO ACTION does. Check the delete rule on every table below the parent. The rule is chosen when the foreign key is defined.
Typical causes
- Removing a duplicate or test record that has picked up real child rows (accounts, orders).
- A clean-up script that deletes parents before children.
- A program that deletes a row it thinks is unused.
Where to look
- The relationship name in DSNT408I, and the foreign key it belongs to (the catalog table SYSIBM.SYSRELS, or your data model).
- A SELECT on the child table for the parent's key.
How to fix
- Find the child rows.
- Decide what they should belong to. A duplicate parent usually means moving the children to the real parent with an UPDATE.
- Then delete the parent.
- Only delete children when the business confirms they are really unwanted.
Interview question
A DELETE of a customer fails with -532. What does that tell you and what do you do?
Stuck on something else?
Ask the community or search the full course.