ON DELETE RESTRICT
ON DELETE RESTRICT is a SQL statement in the Constraints category. Prevents deletion of a parent row if child rows exist. Similar to NO ACTION but checked immediately. The syntax is FOREIGN KEY (col) REFERENCES parent(id) ON DELETE RESTRICT;. It returns restrict constraint. A typical example: CREATE TABLE orders ( id INT PRIMARY KEY, customer_id INT, FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE RESTRICT ); DELETE FROM customers WHERE id = 5; -- ERROR: orders exist for this customer -- Unlike NO ACTION (deferred), RESTRICT is checked immediately -- In practice, most databases implement them identically -- Alternative: CASCADE or SET NULL or SET DEFAULT -- Choose based on business requirements A close relative is PRIMARY KEY, which a column or set of columns that uniquely identifies each row. Only one PK per table. Automatically creates a unique index. A close relative is FOREIGN KEY, which ensures referential integrity: values in this column must exist in the referenced parent table.