
ISOLATION
Initial Check SELECT * FROM accounts; Explanation: I checked the initial data. Alice has 1000 and Bob has 500. Case 1: READ COMMITTED (default) Session 1 BEGIN; UPDATE accounts SET balance = balance - 800 WHERE name = 'Alice'; Explanation: I started a transaction and deducted 800 from Alice. I did not commit, so this change is temporary. Session 2 BEGIN; SELECT balance FROM accounts WHERE name = 'Alice'; Explanation: I checked Alice’s balance in another session. It still shows 1000. What should happen: It should show old value What should not happen: It should not show updated value (200) Reason: Uncommitted data is not visible Session 2 tries update UPDATE accounts SET balance = balance - 500 WHERE name = 'Alice'; Explanation: This query does not run immediately. It waits. What should happen: It should wait What should not happen: It should not update instantly Reason: Row is locked by session 1 Session 1 commit COMMIT; Explanation: Now the change becomes permanent. Session 2 will now
Continue reading on Dev.to
Opens in a new tab




