What happens to children when the parent dies
When you declare a foreign key, you can specify the referential action SQLite takes when the parent row is deleted or updated. The four meaningful options:
- NO ACTION (default) — reject the delete/update if it would orphan child rows.
- RESTRICT — same as NO ACTION but enforced earlier (immediate, not deferred).
- CASCADE — delete (or update) the child rows along with the parent.
- SET NULL — null out the child's FK column. Requires the column to be nullable.
- SET DEFAULT — replace with the column's default value.
Warning:
ON DELETE CASCADE on a parent table can wipe huge subtrees in one statement. That's the point — but it also means a typoed DELETE can do enormous damage. For high-stakes parent tables, prefer NO ACTION + an explicit cleanup query, or wrap the delete in a transaction with a safety check.