Soft delete via trigger
SQL
Hard
0 views
Problem Description
Instead of physically deleting a customer, do a soft delete: set is_active=0 and stop the DELETE. Use a BEFORE DELETE trigger to enforce this rule.
Output Format
Trigger created
Sample Test Case
Input:
Customers(is_active)
Constraints
MySQL-style trigger pattern
Official Solution
CREATE TRIGGER trg_customer_soft_delete BEFORE DELETE ON Customers FOR EACH ROW BEGIN UPDATE Customers SET is_active = 0 WHERE customer_id = OLD.customer_id; SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Soft delete applied; use UPDATE instead of DELETE'; END;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!