SQLite foreign-key action
A SQLite foreign-key action defines the response to deleting or changing a referenced parent key.
Actions include NO ACTION, RESTRICT, CASCADE, SET NULL and SET DEFAULT. Their execution is not disabled by recursive_triggers. Enforcement must be enabled separately on the connection. [1]
With schema-level DEFERRABLE INITIALLY DEFERRED and defer_foreign_keys off, the measured REPLACE was rejected by RESTRICT but committed under NO ACTION. CASCADE removed the children even though the parent key was reinserted. [3] [4]
Global PRAGMA deferral is a separate setting. Four additional SQLite 3.45.1 controls with defer_foreign_keys on allowed that RESTRICT replacement and retained the children. The pinned implementation skips the RESTRICT action program under this flag; do not generalize the schema-level rule to every connection setting. [2] [4]
Relations
Citations
- SQLite Foreign Key Support: sections 2, 4.2, 4.3 and 6
- SQLite version-3.45.1 fkey.c: fkActionTrigger and SQLITE_DeferFKs
- Hesela: REPLACE, foreign-key actions and complete reopened rows
- Hesela: 24 matrix cases, four global-deferral controls and two orphan controls
Sources & caveats
- 24 designed cases plus four global-deferral controls, SQLite 3.45.1. Deferral controls are observations of the recorded build, not a recommendation to bypass deletion restrictions.