100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
SQL Mastery
35 minbeginner

Transactions & ACID Properties

Many real operations require several changes that must all succeed together or not at all. Transferring a player between teams might update two tables; if one update succeeds and the other fails, the data is left inconsistent. A transaction groups multiple statements into a single all-or-nothing unit, so either every change is applied together or none is, keeping the database always in a valid state.

Transactions are bounded by BEGIN, which starts them, and COMMIT, which makes their changes permanent, or ROLLBACK, which discards them entirely. Within a transaction you can run many statements, and only at COMMIT do they become visible and durable. This gives you a safety net: if anything goes wrong partway through, ROLLBACK restores the state as if nothing happened.

The guarantees transactions provide are summarised by ACID: Atomicity, Consistency, Isolation, and Durability. These four properties are why databases can be trusted with money, bookings, and any data where partial or conflicting changes would be catastrophic. Understanding ACID turns transactions from a vague safety feature into a precise tool for reasoning about correctness under failure and concurrency.

Analogy🏏Cricket
🏏 Think of it like cricket: Imagine the end of an IPL innings when the scorer announces the team's final total. Just as the scorer does not read out all one hundred and twenty individual deliveries but instead sums them into a single team score, SUM folds many row values into one number. Just as the commentator reports the highest individual score, the average partnership, and the number of wickets, MAX, AVG, and COUNT each summarise the innings differently. Just as a not-out batsman with no deliveries faced does not lower the team average, aggregates skip NULLs when computing. Just as the announcement is one figure no matter whether the innings had fifty deliveries or two hundred and fifty, an aggregate collapses any number of rows into a single result. This reveals why summaries answer the questions about the whole that individual deliveries cannot.
Lesson 26 of 35
0% complete