Learn VisualLearn DB

Decide What a Parent Delete Means

ON DELETE defines how deleting a parent affects referencing rows — for example, what happens to an order's line items (order_items) when the order itself is deleted. PostgreSQL defaults to NO ACTION. RESTRICT refuses the delete, CASCADE deletes the children too, and SET NULL removes the reference when the child column permits NULL.

GOAL

Choose NO ACTION, RESTRICT, CASCADE, or SET NULL from a requirement.

Why is SET NULL invalid for a NOT NULL foreign-key column?