Savepoint and rollback partially
SQL
Easy
3 views
Problem Description
You are inserting an order and items. If one item insert fails, rollback only item inserts but keep the order row. Use SAVEPOINT.
Sample Test Case
Input:
Orders, OrderItems
Constraints
Use SAVEPOINT
Official Solution
BEGIN; INSERT INTO Orders(order_id, customer_id, order_date, status, total_amount) VALUES (9001, 101, CURRENT_DATE, 'NEW', 0); SAVEPOINT after_order; INSERT INTO OrderItems(order_id, product_id, qty, price) VALUES (9001, 11, 1, 500); ROLLBACK TO after_order; COMMIT;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!