🗃️What is Transaction ?
Describe about What is transaction
Transaction is a collection of queries that we treat as single unit. If some part of queries is failed then it should be rollback.
-- Example We try to transger money from Account A to Account B
----------- ---------
Account_ID | Balance |
----------- ---------
1 | 900 |
2 | 500 |
---------------------
-- Transaction
(1) Query
-- We need to check the balance of account A that it has enough money for tranfer
SELECT Balance from Account where Account_ID = 1
(2) Query
-- Update Balance in Account A
UPDATE Account SET balance = balance - 100 where Account_ID = 1
(3) Query
-- Update Balance in Account B
UPDATE Account SET balance = balance + 100 where Account_ID = 2
Last updated