Avoid dirty writes
SQL
Easy
2 views
Problem Description
Show that you should lock a row before updating by using SELECT ... FOR UPDATE.
Sample Test Case
Output:
Row locked then updated
Constraints
Works in many DBs
Official Solution
BEGIN; SELECT balance FROM Accounts WHERE acc_id=1 FOR UPDATE; UPDATE Accounts SET balance = balance - 100 WHERE acc_id=1; COMMIT;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!