#823

Transfer money between accounts without overdraft

A classic two-bank-accounts-and-a-transfer task. If you just read both balances and update them without locks, two parallel transactions can see the same state and both deduct the money — the account ends up negative. Inside a single transaction transfer 200 from Anna's account (id 1) to Bob's (id 2): first lock both rows for the rest of the transaction in write mode, then with two updates deduct 200 from Anna and credit 200 to Bob.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.

idholderbalance
1Аня800.00
2Боб700.00

Your query result will appear here