DataBolt

SQL LEARNING PLATFORM

26

CHAPTER 26

Transactions & ACID

Data integrity — guaranteeing your data is always correct.

3

Learning Blocks

SQL

Interactive Queries

In This Chapter

Concepts you'll master

1

What a transaction is and why it matters

2

START TRANSACTION, COMMIT, ROLLBACK

3

ACID: Atomicity, Consistency, Isolation, Durability

4

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
SQL QUERY
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