ALTER FOREIGN KEY CONSTRAINT
Changes the deferrability of an existing foreign key without recreating the constraint.
ALTER TABLE child
ALTER CONSTRAINT child_parent DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE child
ALTER CONSTRAINT child_parent DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE child
ALTER CONSTRAINT child_parent NOT DEFERRABLE;
The target must be an existing foreign key on the named table. DEFERRABLE
allows the foreign key to be controlled by SET CONSTRAINTS;
INITIALLY DEFERRED starts it deferred in each new transaction, while
INITIALLY IMMEDIATE checks it normally.
If INITIALLY ... is omitted, the current value is preserved. With
NOT DEFERRABLE, initially_deferred is normalized to false.
The change is transactional DDL: inside BEGIN it can be undone by
ROLLBACK; outside an explicit transaction, it commits at the end of the
statement. Foreign keys with a RESTRICT referential action cannot be made
deferrable in this version.
The Web Console shows persisted values in the constraints table as read-only checkboxes. The change is executed through the SQL editor.