Archive deleted rows using trigger
SQL
Hard
0 views
Problem Description
When a customer row is deleted, copy it into DeletedCustomers(customer_id, name, deleted_at) before deletion.
Output Format
Trigger created
Sample Test Case
Input:
Customers, DeletedCustomers
Constraints
DeletedCustomers table must exist
Official Solution
CREATE TRIGGER trg_customers_archive BEFORE DELETE ON Customers FOR EACH ROW INSERT INTO DeletedCustomers(customer_id, name, deleted_at) VALUES (OLD.customer_id, OLD.name, CURRENT_TIMESTAMP);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!