CS FundamentalsModerateTCS NQT · Infosys pattern

A transaction executes `BEGIN; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; COMMIT;` and the system crashes after the first UPDATE is written to disk but before COMMIT. What should recovery do?

  1. A. Leave the database in whatever state the crash left it, with no recovery action needed
  2. B. Keep the first UPDATE's effect and skip the second, since partial progress is better than none
  3. C. Roll back the first UPDATE's effect entirely, since the transaction never committed — atomicity requires all-or-nothing
  4. D. Apply the second UPDATE automatically to 'complete' the transaction

Correct answer: C. Roll back the first UPDATE's effect entirely, since the transaction never committed — atomicity requires all-or-nothing

Atomicity guarantees a transaction's effects are either entirely applied or entirely undone. Since COMMIT was never reached, recovery's undo pass must reverse the first UPDATE (using the log's before-image/undo information) so the transaction has no partial, inconsistent effect on the database.

More DBMS and SQL questions

Exams that ask this topic