PRAGMA defer_foreign_keys
When the defer_foreign_keys PRAGMA is on, enforcement of all foreign key constraints is delayed until the outermost transaction is committed.
PRAGMA defer_foreign_keys PRAGMA defer_foreign_keys = boolean;
On the sample database
What PRAGMA defer_foreign_keys returns on the sample database, in SQLite 3.54.1 as built for the browser by sql.js:
| defer_foreign_keys |
|---|
| 0 |
What the SQLite documentation says
When the defer_foreign_keys PRAGMA is on, enforcement of all foreign key constraints is delayed until the outermost transaction is committed. The defer_foreign_keys pragma defaults to OFF so that foreign key constraints are only deferred if they are created as "DEFERRABLE INITIALLY DEFERRED". The defer_foreign_keys pragma is automatically switched off at each COMMIT or ROLLBACK. Hence, the defer_foreign_keys pragma must be separately enabled for each transaction. This pragma is only meaningful if foreign key constraints are enabled, of course.
The sqlite3_db_status(db,SQLITE_DBSTATUS_DEFERRED_FKS,...) C-language interface can be used during a transaction to determine if there are deferred and unresolved foreign key constraints.
Caution: Setting "defer_foreign_keys=0" resets the internal foreign-key tracking state of the database connection, so that it becomes possible to commit the current transaction even if there are foreign key violations.
From sqlite.org's pragma documentation for SQLite 3.54.1, in the public domain.