Deferred Constraints
Constraints that defer their enforcement check until the end of a transaction rather than immediately after each statement.
DEFERRABLE INITIALLY DEFERRED INITIALLY IMMEDIATE SET CONSTRAINTS deferred constraint
constraint deferred transaction DEFERRABLE integrity
| Database | Status | Syntax Family | Min Version |
|---|---|---|---|
| PostgreSQL | full | sql-standard | - |
| MySQL | none | - | - |
| MariaDB | none | - | - |
| Oracle | full | sql-standard | - |
| SQL Server | none | - | - |
| SQLite | partial | deferred-fk | - |
| Redshift | none | - | - |
| DB2 | workaround | set-integrity | - |
| Snowflake | none | - | - |
| BigQuery | none | - | - |
Compare Databases
Database Details
PostgreSQL
full
-- Declare a deferrable FK at creation time
ALTER TABLE orders
ADD CONSTRAINT fk_orders_customer
FOREIGN KEY (customer_id)
REFERENCES customers (id)
DEFERRABLE INITIALLY DEFERRED;
-- Defer all deferrable constraints for this transaction
BEGIN;
SET CONSTRAINTS ALL DEFERRED;
-- ... insert rows that temporarily violate FKs ...
COMMIT;
-- Defer a specific constraint
SET CONSTRAINTS fk_orders_customer DEFERRED;- UNIQUE, PRIMARY KEY, FOREIGN KEY, and EXCLUDE can all be DEFERRABLE.
- INITIALLY DEFERRED defers by default each transaction; INITIALLY IMMEDIATE is the default and can be switched mid-transaction with SET CONSTRAINTS.
- NOT DEFERRABLE is locked — SET CONSTRAINTS has no effect.
MySQL
none
- Not supported; constraints fire per statement. SET FOREIGN_KEY_CHECKS = 0 disables FK enforcement session-wide, which is different from (and more dangerous than) deferring it.
Docs: FOREIGN KEY Constraints
MariaDB
none
- Same as MySQL: no deferral; SET FOREIGN_KEY_CHECKS = 0 is a disable, not a defer.
Docs: Foreign Keys
Oracle
full
-- Declare a deferrable FK
ALTER TABLE orders
ADD CONSTRAINT fk_orders_customer
FOREIGN KEY (customer_id)
REFERENCES customers (id)
DEFERRABLE INITIALLY DEFERRED;
-- Defer a specific constraint within a transaction
SET CONSTRAINT fk_orders_customer DEFERRED;
-- Defer all deferrable constraints
SET CONSTRAINTS ALL DEFERRED;- UNIQUE, PRIMARY KEY, and FOREIGN KEY can be DEFERRABLE. EXCLUDE doesn't exist here.
- SET CONSTRAINT (singular) and SET CONSTRAINTS (plural) both work. A deferred-check violation rolls the whole transaction back at COMMIT.
SQL Server
none
- Not supported. ALTER TABLE ... NOCHECK CONSTRAINT disables a constraint entirely rather than deferring it — not equivalent.
Docs: Disable Constraints
SQLite
partial
-- Defer FK checks for the entire transaction
PRAGMA defer_foreign_keys = ON;
BEGIN;
-- ... operations that temporarily violate FKs ...
COMMIT;
-- FK checks run at COMMIT- Foreign keys only. PRAGMA defer_foreign_keys = ON defers every FK check in the current transaction and resets at transaction end.
- UNIQUE and CHECK cannot be deferred, and FK-level DEFERRABLE isn't fully wired up.
DB2
workaround
-- Bulk-load style deferred validation
SET INTEGRITY FOR orders OFF;
-- ... load or alter data while integrity is pending ...
SET INTEGRITY FOR orders IMMEDIATE CHECKED;- No DEFERRABLE. SET INTEGRITY suspends and revalidates table-level integrity for bulk-load and maintenance workflows, not per-transaction.