
ATOMICITY
In this task I am checking atomicity. That means a transaction should either fully complete or not happen at all. First I check the initial data. Query select * from accounts; Here I see Alice has 1000 and Bob has 500. Now I perform a correct transfer. Query begin; update accounts set balance = balance - 300 where name = 'Alice'; update accounts set balance = balance + 300 where name = 'Bob'; commit; Here I deducted 300 from Alice and added 300 to Bob in the same transaction. Now I check the data. Query select * from accounts; Now Alice has 700 and Bob has 800. So both operations happened successfully. Now I test what happens if something goes wrong after deducting money. Query begin; update accounts set balance = balance - 200 where name = 'Alice'; Now I introduce an error. I write a wrong column name. update accounts set bal = balance + 200 where name = 'Bob'; commit; Here the second query fails because column bal does not exist. Now I check the data again. Query select * from accoun
Continue reading on Dev.to Tutorial
Opens in a new tab




