Prevent deleting parent rows when children exist
SQL
Medium
9 views
Problem Description
In Orders(order_id) and Payments(payment_id, order_id), enforce that an order cannot be deleted if it has payments.
Output Format
DDL statement(s)
Constraints
Assume Orders exists
Official Solution
ALTER TABLE Payments ADD CONSTRAINT fk_payments_orders FOREIGN KEY (order_id) REFERENCES Orders(order_id) ON DELETE RESTRICT;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!