DataBolt

All Lessons

Introduction to SQL
SQL Lesson 1: Your Sample Database
SQL Lesson 2: SELECT — Reading data
SQL Lesson 3: WHERE — Filtering rows
SQL Lesson 4: AND, OR, NOT
SQL Lesson 5: BETWEEN, IN, LIKE
SQL Lesson 6: NULL — The Mystery Value
SQL Lesson 7: ORDER BY
SQL Lesson 8: LIMIT & OFFSET
SQL Lesson 9: Aggregate Functions
SQL Lesson 10: GROUP BY
SQL Lesson 11: HAVING
SQL Lesson 12: INNER JOINs
SQL Lesson 13: LEFT JOINs
SQL Lesson 14: RIGHT JOINs
SQL Lesson 15: SELF JOINs
SQL Lesson 16: UNION JOINs
SQL Lesson 17: Joining Multiple Tables
SQL Lesson 18: Subqueries
SQL Lesson 19: CTEs (WITH)
SQL Lesson 20: CASE Statements
SQL Lesson 21: Window Functions
SQL Lesson 22: String Functions
SQL Lesson 23: Date & Time Functions
SQL Lesson 24: INSERT, UPDATE, DELETE
SQL Lesson 25: CREATE TABLE & DDL
SQL Lesson 26: Indexes & Performance
SQL Lesson 27: Transactions & ACID
SQL Lesson 28: SQL Execution Order
SQL Lesson 29: 50 Practice Problems

CHAPTER 28

Transactions & ACID

Data integrity — guaranteeing your data is always correct.

IN THIS CHAPTER

  • What a transaction is and why it matters
  • START TRANSACTION, COMMIT, ROLLBACK
  • ACID: Atomicity, Consistency, Isolation, Durability
  • SAVEPOINT for partial rollbacks

🌟 Think of it this way: A bank transfer: deduct ₹5,000 from Account A, add ₹5,000 to Account B. If the server crashes after the deduction but before the credit, the money disappears. A transaction guarantees either BOTH operations succeed or NEITHER does — the money cannot vanish.

Safe money transfer

START TRANSACTION;
UPDATE accounts SET balance = balance - 5000 WHERE account_id =
101;
UPDATE accounts SET balance = balance + 5000 WHERE account_id =
202;
COMMIT; -- only if both succeed
-- If anything fails:
ROLLBACK; -- reverts both updates completely

PropertyGuaranteeBank Transfer Example
AtomicityAll changes commit or none doDebit + credit both happen or neither
ConsistencyDB remains valid before and afterTotal money in system stays the same
IsolationConcurrent transactions do not interfereTwo simultaneous transfers do not corrupt each other
DurabilityCommitted data survives crashesAfter COMMIT, data is on disk even if power cuts