Problem Statement
Which precaution helps prevent unexpected large deletions when using ON DELETE CASCADE?
Explanation
CASCADE can remove deep trees. Wrap deletes in a transaction, check impact with a SELECT first, and delete in small batches if needed.
Keep foreign keys explicit and ensure only intended users can perform destructive actions.
Code Solution
SolutionRead Only
BEGIN; -- preview SELECT COUNT(*) FROM orders WHERE customer_id = :id; -- then delete parent DELETE FROM customers WHERE id = :id; COMMIT;
Practice Sets
This question appears in the following practice sets:
