Database.What are the main properties of a transaction?

The main properties of a transaction are summarized by the acronym ACID, which ensures reliability and consistency in database operations.


🔐 ACID Properties:

PropertyDescription
A – AtomicityA transaction is all-or-nothing: either every operation succeeds, or none do. If any part fails, the entire transaction is rolled back.
C – ConsistencyA transaction takes the database from one valid state to another, preserving all defined rules, constraints, and relationships.
I – IsolationEach transaction is executed as if it were the only one running. Concurrent transactions don’t interfere with each other’s data.
D – DurabilityOnce 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 COMMIT runs, the transfer is saved
This entry was posted in Без рубрики. Bookmark the permalink.