Learn Programming, Tech & Coding · Free Online Tools

IT Question Answer
Back to Database
Database Transactions and ACID Properties

Database Transactions and ACID Properties

Database388 viewsBy Admin
databasetransactionsacidproperties

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

PropertyMeaning
AtomicityAll or nothing
ConsistencyValid state to valid state
IsolationConcurrent transactions don't interfere
DurabilityCommitted 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.