The REFERENCES clause is part of the SQL DDL and appears in CREATE TABLE and ALTER TABLE statements. It declares that the column or column list in the child table must match values that already exist in the referenced (parent) table’s primary key or unique key. When the constraint is active, the database automatically rejects INSERT, UPDATE, or DELETE operations that would break the relationship unless cascading actions are specified. A REFERENCES clause can be defined inline (right after the column) or as a separate table-level FOREIGN KEY constraint. Optional ON DELETE and ON UPDATE actions (CASCADE, SET NULL, SET DEFAULT, RESTRICT, NO ACTION) let you control what happens to child rows when parent rows change. Some dialects also allow MATCH options (SIMPLE, FULL) and deferrable constraints. Because REFERENCES depends on indexes in the parent table, the referenced columns must be declared PRIMARY KEY or UNIQUE. Failing to meet this requirement raises an error at table creation.
parent_table
(identifier) - Name of the table being referenced.parent_column(s) (identifier list)
- Column or columns in the parent table that form a PRIMARY KEY or UNIQUE constraint.action
(keyword) - CASCADE | SET NULL | SET DEFAULT | RESTRICT | NO ACTION.MATCH option
(keyword, optional) - SIMPLE | FULL (supported in PostgreSQL, etc.).DEFERRABLE settings
(optional) - DEFERRABLE | NOT DEFERRABLE INITIALLY DEFERRED | INITIALLY IMMEDIATE.FOREIGN KEY, PRIMARY KEY, UNIQUE, ON DELETE, ON UPDATE, CASCADE, ALTER TABLE, DEFERRABLE
SQL-92 standard
Inline REFERENCES is placed right after a column definition and can reference a single column only. Table-level REFERENCES appears after all columns, lets you name the constraint, and supports multi-column keys.
Most databases automatically index primary keys but not foreign-key columns. Adding an index on the child column(s) greatly speeds up JOINs and DELETE/UPDATE checks.
The default is usually NO ACTION (or RESTRICT). The database blocks parent deletes or key updates that would leave orphaned child rows.
Yes, in databases that support DEFERRABLE constraints (PostgreSQL, Oracle). Declare the constraint DEFERRABLE INITIALLY DEFERRED and the check occurs at transaction commit instead of per statement.