FOREIGN KEY ON DELETE SET NULL
FOREIGN KEY ON DELETE SET NULL is a SQL statement in the Constraints category. When the parent row is deleted, child's foreign key is set to NULL instead of being deleted. The syntax is FOREIGN KEY (col) REFERENCES parent(id) ON DELETE SET NULL;. It returns constraint with SET NULL. A typical example: CREATE TABLE orders ( id INT PRIMARY KEY, user_id INT, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL ); -- When user is deleted, order.user_id becomes NULL -- Order records are preserved 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. A close relative is UNIQUE, which ensures all values in a column (or combination) are unique across the table. Allows NULLs (multiple NULLs allowed).