Transactions and ACID
What a transaction is (a unit of work made of reads, writes, commit and abort), its states, the four ACID properties and which part of the system guarantees each one, and the anomalies that appear when transactions run without control (lost update, dirty read, non-repeatable read, inconsistent summary, crash in the middle of a transfer), each shown as a schedule executed on real numbers; the SQL isolation levels are described as quoted from the standard.
Why it exists
A bank transfer is two writes: subtract from one account, add to another. If the machine stops between the writes, or another program reads the accounts in between, the data are wrong. A transaction groups operations into one unit that the database system promises to run all or nothing and as if alone. This page defines the unit and the four promises (ACID); the next pages study how the promises are kept for several transactions at once.
Prerequisites
None. Knowing what a table and a record are is enough (relational model if you want the vocabulary).
Precise definitions
A transaction is a sequence of operations on database items that the system treats as one logical unit. In the theory used for GATE only these operations are visible:
- : transaction reads item (a record, a block, a value: the unit is called an item);
- : writes item ;
- : commits (its effects become permanent);
- : aborts (its effects are undone).
Each transaction ends with exactly one of commit or abort. A schedule (or history) of several transactions is an interleaving of their operations that keeps the order inside each transaction.
States of a transaction (as in the textbooks; the names differ slightly): active (executing), partially committed (the last operation has run, the commit is not yet safe on disk), committed, failed (it cannot continue) and aborted (rolled back, the database is as before it started; the transaction can then be restarted or killed).
| from | to | because |
|---|---|---|
| active | partially committed | the last operation has been executed |
| active | failed | an error or a deadlock victim |
| partially committed | committed | the system has made the effects durable (log written) |
| partially committed | failed | the commit could not be completed |
| failed | aborted | rollback finished |
The ACID properties:
| letter | property | meaning | who guarantees it |
|---|---|---|---|
| A | Atomicity | all the operations of the transaction take effect or none does | recovery manager (undo using a log) |
| C | Consistency | a transaction that starts in a consistent state (all integrity constraints hold) ends in a consistent state | the programmer who writes the transaction and the integrity constraints; the system checks the constraints |
| I | Isolation | each transaction behaves as if it ran alone; concurrent execution is equivalent to a serial one | concurrency control (locking, timestamps) |
| D | Durability | after commit the effects survive any failure | recovery manager (redo using a log, forced to disk before the commit) |
Consistency is the only property that is not provided by a mechanism alone: if every transaction is correct when it runs alone, then atomicity and isolation together keep the database consistent.
How it works
The five things that go wrong
Each animation below runs the transactions on real numbers. unless stated.
Lost update. Two transactions read the same value and both write a result computed from it.
Lost update: two transactions read the same balance: start
Computed by a script, not typed| time | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| T1 | ||||||
| T2 | ||||||
| database |
Step 0
A = 100. T1 withdraws 30, T2 deposits 50. Both read before either writes.
The final value is ; every serial execution gives . The update of is lost although both transactions committed.
Dirty read (write-read conflict). A transaction reads a value written by a transaction that has not committed and later aborts.
Dirty read: reading what a transaction later undoes: start
Computed by a script, not typed| time | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| T1 | |||||
| T2 | |||||
| database |
Step 0
A = 100. T1 withdraws 30 but will abort.
has used the value , which was removed by the abort.
Non-repeatable read (read-write conflict). A transaction reads the same item twice and gets two values because another transaction committed a change in between.
Non-repeatable read: start
Computed by a script, not typed| time | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| T1 | ||||||
| T2 | ||||||
| database |
Step 0
A = 100. T1 reads A twice; T2 changes A between the reads.
Inconsistent summary (also called incorrect summary). A transaction that reads several items sees some of them before and some after another transaction's updates.
Inconsistent summary: reading in the middle of a transfer: start
Computed by a script, not typed| time | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| T1 | ||||||||
| T2 | ||||||||
| database |
Step 0
A = 100, B = 50, total 150. T1 moves 40 from A to B; T2 adds A and B.
computes although the total is before and after the transfer.
Failure in the middle (violates atomicity):
Why atomicity needs recovery: a crash in the middle of a transfer: start
Computed by a script, not typed| time | 1 | 2 | 3 |
|---|---|---|---|
| T1 | |||
| database |
Step 0
A = 100, B = 50. T1 transfers 40 from A to B and the machine crashes after the first write.
The textbooks add the phantom problem: a transaction runs a query with a condition twice and a second run returns an extra row inserted meanwhile by another transaction (the item-based model above does not show it because it has no insertions).
Isolation levels in SQL (quoted)
The SQL standard defines four levels by the anomalies they allow. The following table is quoted from the standard as the textbooks present it and needs verification against the edition you study; implementations differ.
| level | dirty read | non-repeatable read | phantom |
|---|---|---|---|
| READ UNCOMMITTED | possible | possible | possible |
| READ COMMITTED | prevented | possible | possible |
| REPEATABLE READ | prevented | prevented | possible |
| SERIALIZABLE | prevented | prevented | prevented |
SERIALIZABLE means that the outcome equals that of some serial execution; the next pages make this precise.
Worked examples
EX 1Name the property
Easy(a) A transfer leaves debited and not credited after a crash: atomicity. (b) After the system confirmed a payment, a power failure erases it: durability. (c) Two transactions interfere so that the result matches no serial order: isolation. (d) The total of all balances must stay constant, and each transfer keeps it constant: consistency.
EX 2Which anomaly
Medium: reads a value of an uncommitted transaction that then aborts: a dirty read. : both overwrite from the same old value: a lost update. : non-repeatable read.
EX 3Numbers of the lost update
Medium, : , : . Serial: in either order. The interleaving writes and then : result . With the result would be . Both are wrong, in different ways.
EX 4Typical questions
GATE level(a) "Which ACID property is ensured by the recovery manager?" Atomicity and durability. (b) "Which by the concurrency control manager?" Isolation. (c) "A transaction that has issued its last operation but whose log is not yet on disk is in which state?" Partially committed. (d) "After rollback a transaction can be restarted": true for aborted transactions caused by a hardware or software error that is not an internal logical error; it may be killed.
Cheat box
Cheat box
- Transaction: unit of work, ends with commit or abort. Operations , , , .
- ACID: atomicity and durability (recovery manager, log); isolation (concurrency control); consistency (programmer plus constraints).
- States: active, partially committed, committed, failed, aborted.
- Anomalies: lost update (WW), dirty read (WR), non-repeatable read (RW), inconsistent summary, phantom.
- Serializable is the strongest isolation level; READ UNCOMMITTED the weakest.
Traps and GATE patterns
Connections
Builds on
No prerequisites.
Across subjects
No cross-subject links yet.
Isolation is made precise by serializability and enforced by locking; the interaction of aborts with reads is the subject of recoverability; atomicity and durability are implemented by log-based recovery.
PYQs
6 previous year questions from your book. I re-solved each one myself (1 by running or simulating, 5 by reasoning only); the book's key is shown next to my answer. All PYQs
A company maintains records of sales made by its salespersons and pays them commission based on each individual's total sales made in a year. This data is maintained in a table with following schema: salesinfo = (salespersonid, totalsales, commission) In a certain year, due to better business results, the company decides to further reward its salespersons by enhancing the commission paid to them as per the following formula: If commission < = 50000, enhance it by 2% If 50000 < commission < = 100000, enhance it by 4% If commission > 100000, enhance it by 6% The IT staff has written three different SQL scripts to calculate enhancement for each slab, each of these scripts is to run as a separate transaction as follows: DATABASE MANAGEMENT SYSTEM T1 Update salesinfo Set commission = commission * 1.02 Where commission < = 50000; T2 Update salesinfo Set commission = commission * 1.04 Where commission > 50000 and commission is < = 100000; T3 Update salesinfo Set commission = commission * 1.06 Where commission > 100000; Which of the following options of running these transactions will update the commission of all salespersons correctly
- (a)Execute T1 followed by T2 followed by T3
- (b)Execute T2, followed by T3; T1 running concurrently throughout
- (c)Execute T3 followed by T2; T1 running concurrently throughout
- (d)Execute T3 followed by T2 followed by T1
An audit of a banking transactions system has found that on an earlier occasion, two joint holders of account A attempted simultaneous transfers of Rs. 10000 each from account A to account B. Both transactions read the same value, Rs. 11000, as the initial balance in A and were allowed to go through. B was credited Rs. 10000 twice. A was debited only once and ended up with a balance of Rs. 1000. Which of the following properties is/are certain to have been violated by the system?
- (a)Atomicity
- (b)Consistency
- (c)Isolation
- (d)Durability
Once the DBMS informs the user that a transaction has been successfully completed, its effect should persist even if the system crashes before all its changes are reflected on disk. This property is called
- (a)Durability
- (b)Atomicity
- (c)Consistency
- (d)Isolation DATABASE MANAGEMENT SYSTEM
Which one of the following is NOT a part of the ACID properties of database transactions?
- (a)Atomicity
- (b)Consistency
- (c)Isolation
- (d)Deadlock-freedom DATABASE MANAGEMENT SYSTEM
Consider the following transaction involving two bank accounts x and y. read (x) ; x : =x - 50; write (x) ; read (y); y : = y + 50; write (y) The constraint that the sum of the accounts x and y should remain constant is that of DATABASE MANAGEMENT SYSTEM
- (a)Atomicity
- (b)Consistency
- (c)Isolation
- (d)Durability
Amongst the ACID properties of a transaction, the 'Durability' property requires that the changes made to the database by a successful transaction persist
- (a)Except in case of an Operating System crash
- (b)Except in case of a Disk crash
- (c)Except in case of a power failure
- (d)Always, even if there is a failure of any kind of failure
Self-check
Question 1
Which ACID property does the lost update violate?
Show answerHide
Isolation: the result is not that of any serial execution.
Question 2
and . moves from to and crashes after writing . What does a correct system do after the crash?
Show answerHide
It undoes the write of (atomicity), restoring , ; the total stays .
Question 3
Which anomaly is it if reads twice and sees two values?
Show answerHide
A non-repeatable read, caused by a committed write of another transaction between the reads.
Revision card
One-screen revision
- Transaction = all-or-nothing unit; ends with commit or abort.
- A, D: recovery manager; I: concurrency control; C: programmer and constraints.
- Anomalies: lost update, dirty read, non-repeatable read, inconsistent summary, phantom.
- States: active, partially committed, committed, failed, aborted.
References
- ·Silberschatz, Korth, Sudarshan, Database System Concepts (7th edition), Chapter 17 (Transactions)
- ·Elmasri, Navathe, Fundamentals of Database Systems (7th edition), Chapter 20 (Introduction to Transaction Processing Concepts and Theory)
Verification
Every anomaly animation executes the transactions on real numbers in scripts/db_txn.py (execute), including the restoration of before-images on abort; the numbers on the page (150 instead of 120, 110 instead of 150) are those outputs. The final values of the serial executions were asserted in scripts/gen-db5-traces.py. The five transaction states and the table of SQL isolation levels are QUOTED from the textbooks and the SQL standard and need verification against the editions used; real database systems differ from the standard table (their levels are implemented with locks or multiversion snapshots), and SQLite, used as the oracle elsewhere in this subject, only offers serializable behaviour. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and re-derived against the textbook definitions and the sample database. No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)