CASCADE Delete
Question
What does ON DELETE CASCADE do?
Hint
CASCADE propagates deletes to foreign key references.
Explanation
ON DELETE CASCADE is a foreign key constraint option that automatically deletes dependent (child) rows when the parent row is deleted. Example: orders.customer_id REFERENCES customers(id) ON DELETE CASCADE — deleting a customer automatically deletes all their orders. This maintains referential integrity without manual cleanup. Use with caution — cascading deletes can remove large amounts of data unexpectedly. Alternatives: ON DELETE SET NULL (set FK to NULL), ON DELETE RESTRICT (prevent deletion), ON DELETE NO ACTION (same as RESTRICT). CASCADE is useful for parent-child relationships where children are meaningless without the parent.
Related Resources
Related Lessons
- Relationships
Learn relationships.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.