ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

SQL Database Tutorial• 7 min read

ACID Transactions & Concurrency Control

Atomicity, Consistency, Isolation, Durability, row locks, and isolation levels

A database transaction is a logical unit of work consisting of multiple operations that must succeed or fail as a single indivisible unit, adhering to the ACID guarantees.

The 4 Pillars of ACID

1Atomicity: "All or Nothing." If 9 out of 10 statements succeed but the 10th fails, the entire transaction is rolled back with zero partial writes.
2Consistency: Any transaction will bring the database from one valid state to another, respecting all constraints and foreign keys.
3Isolation: Concurrent transactions cannot interfere with each other or see intermediate uncommitted states.
4Durability: Once a transaction commits, its writes are permanent on disk even during a power outage or OS crash.
Atomic Bank Account Transfer Transaction
BEGIN TRANSACTION;

-- 1. Deduct funds from Alice
UPDATE BankAccounts 
SET Balance = Balance - 500 
WHERE AccountID = 'ACC_ALICE';

-- 2. Credit funds to Bob
UPDATE BankAccounts 
SET Balance = Balance + 500 
WHERE AccountID = 'ACC_BOB';

-- If any step raises an error: ROLLBACK;
-- Otherwise, commit permanently:
COMMIT;
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

What does Atomicity in ACID transactions guarantee?