Two-phase style steps (concept + SQL)
SQL
Hard
2 views
Problem Description
You want to do: reserve stock, then charge payment. Show savepoint usage so payment failure restores stock.
Sample Test Case
Input:
Inventory, Payments
Constraints
Use savepoint between steps
Official Solution
BEGIN; UPDATE Inventory SET qty = qty - 1 WHERE product_id=10 AND qty > 0; SAVEPOINT reserved; INSERT INTO Payments(order_id, amount, paid_at) VALUES (7001, 600, CURRENT_TIMESTAMP); ROLLBACK TO reserved; COMMIT;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!