The main properties of a transaction are summarized by the acronym ACID, which ensures reliability and consistency in database operations.
🔐 ACID Properties:
| Property | Description |
|---|---|
| A – Atomicity | A transaction is all-or-nothing: either every operation succeeds, or none do. If any part fails, the entire transaction is rolled back. |
| C – Consistency | A transaction takes the database from one valid state to another, preserving all defined rules, constraints, and relationships. |
| I – Isolation | Each transaction is executed as if it were the only one running. Concurrent transactions don’t interfere with each other’s data. |
| D – Durability | Once a transaction is committed, its changes are permanent — even if the system crashes immediately afterward. |
🧠 Example: Bank Transfer
BEGIN;
UPDATE Accounts SET balance = balance - 100 WHERE id = 1;
UPDATE Accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
If the system crashes after the first update:
- Atomicity ensures both updates are rolled back
- Consistency ensures no money is lost or created
- Isolation prevents interference from other transfers
- Durability ensures that if
COMMITruns, the transfer is saved