Database Transactions and ACID Properties
Ad
What is a Transaction?
A transaction is a group of operations treated as a single unit — either all succeed or none do. Essential for things like money transfers.
The Classic Example
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT; -- both happen, or ROLLBACK undoes everything
ACID Properties
| Property | Meaning |
|---|---|
| Atomicity | All or nothing |
| Consistency | Valid state to valid state |
| Isolation | Concurrent transactions don't interfere |
| Durability | Committed data survives crashes |
Rolling Back
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
-- error detected!
ROLLBACK; -- undo everything
FAQs
Do NoSQL databases support transactions?
Many now do (MongoDB added multi-document transactions). More in our Database guides.
What are isolation levels?
Settings (Read Committed, Serializable...) that control how transactions see each other's changes.
