DatabaseStatusSyntax FamilyMin 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.
MariaDB none
  • Same as MySQL: no deferral; SET FOREIGN_KEY_CHECKS = 0 is a disable, not a defer.
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.
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.
Redshift none
  • Constraints aren't enforced; deferral doesn't apply.
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.
Snowflake none
  • Constraints aren't enforced; deferral doesn't apply.
BigQuery none
  • Constraints aren't enforced; deferral doesn't apply.