ON DELETE CASCADE

A referential action on a foreign key: when a parent row is deleted, the child rows that reference it are deleted automatically.

sql
FOREIGN KEY (customer_id) REFERENCES customer(customer_id) ON DELETE CASCADE

When to use

Use it when child rows make no sense without their parent, for example rentals that belong to a customer. The study guide's rental table declares it with ON DELETE CASCADE. Its sibling actions are SET NULL and RESTRICT.

See Read 01.

Appears in

No references yet.