Example: Transferring Funds Between Accounts
Consider two bank accounts represented by rows in a database table:- Savings: $20
- Checking: $50

You can also use
ROLLBACK to undo changes if any step fails:Potential Issues Without ACID
- Incomplete transaction: The first update succeeds, but the second one fails, leaving balances inconsistent.
- Interim reads: A third party queries balances after step 1 but before step 2, seeing $10 in savings and $50 in checking (total $60).

ACID Properties Explained
The ACID acronym stands for the four rules that guarantee transaction integrity:| Property | Description |
|---|---|
| Atomicity | Ensures all updates in a transaction succeed or none do (all-or-nothing). |
| Consistency | Guarantees the database moves from one valid state to another (e.g., total balance remains $70). |
| Isolation | Prevents other operations from seeing intermediate states. |
| Durability | Commits survive system failures; changes persist even after a crash. |

Isolation Levels
Different databases support multiple isolation levels (e.g., Read Committed, Serializable). Choose the level that balances concurrency and consistency for your workload.Long-running transactions can block other operations and degrade performance. Keep transactions short and predictable.
Transaction Management: Commit vs. Rollback
At the end of your transaction:- COMMIT: Applies all updates, resulting in $10 in savings and $60 in checking.
- ROLLBACK: Undoes every change, preserving the original $20 and $50 balances.
