Deletion Policies for Referenced Rows
A relationship constraint defines what happens to referencing rows when someone removes a referenced row.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace two possible policies
A session containing bookings may refuse deletion until they are handled. A private record with dependent settings may use cascading deletion according to its lifecycle. Foreign keys express these relationships.
Verify the full effect
Use an isolated fixture with a parent and several children, then verify all expected rows and separate histories. Function postconditions help define the resulting state.[1][2]
Compare policies using the same dependent records
A project can contain tasks. Removing its project row might be rejected, delete tasks under a cascade policy or leave tasks with an absent project when nullable references are allowed. Which result is valid depends on ownership and archive requirements. See foreign-key references.
Project 7 referenced by tasks A and B
Restrict: keep project and tasks, reject delete
Cascade: remove all three under chosen constraints
Set null: tasks remain if reference permits null
Test committed state and effects on readers
A cascade can reach additional dependent tables. A historical app may instead mark a project archived. Test one referenced and one unreferenced parent and verify related visibility afterward.