> For the complete documentation index, see [llms.txt](https://dev7days.gitbook.io/dev7days/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev7days.gitbook.io/dev7days/database/what-is-transaction.md).

# 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.

```sql
-- 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
```
