IBPS IT Officer · Government IT exam preparation
Transactions in DBMS: COMMIT, ROLLBACK and SAVEPOINT
Transaction states and recoverable, cascadeless and strict schedules.
Transactions & schedules: the core idea
A transaction groups database operations into one unit of work. COMMIT successfully ends the transaction and makes its changes committed. ROLLBACK cancels uncommitted work. A SAVEPOINT marks a place inside a transaction that we may roll back to.
A bank transfer has a debit and a credit. Saving only the debit is wrong. A transaction lets us treat both operations as one unit. The application must still check account rules and handle errors correctly.
| Concept | Meaning | Example / distinction |
|---|---|---|
| BEGIN / START TRANSACTION | Start an explicit transaction | Exact syntax varies |
| COMMIT | Commit the transaction | Changes become durable under the configured guarantees |
| ROLLBACK | Cancel uncommitted transaction work | Does not undo a transaction already committed |
| SAVEPOINT | Name a point inside the transaction | A marker, not a final commit |
| ROLLBACK TO SAVEPOINT | Undo work after the marker | Earlier work can remain pending |
| Autocommit | Statements commit separately unless grouped | Driver and system settings differ |
Exam essentials
Transaction states
Active means work is running. Partially committed means the last statement has run but commit is not yet safely completed. Committed means success is finalized. Failed means normal execution cannot continue. Aborted means rollback has restored the required state; a transaction may then restart or terminate.
Serial versus serializable
A serial schedule finishes one transaction before the next starts. A serializable schedule may interleave operations but is equivalent under the chosen criterion to a serial execution. Concurrency is therefore possible without giving up serializability.
Recoverable schedule
If T2 reads a value written by T1, T2 must not commit before T1 commits. This avoids a committed reader depending on a transaction that later aborts. Recoverable schedules may still need cascading rollbacks.
Cascadeless and strict
Cascadeless schedules allow reads only after the writer commits. Strict schedules also prevent another transaction from overwriting an item written by an uncommitted transaction. Strict ⇒ cascadeless ⇒ recoverable. The reverse implications do not always hold.
SAVEPOINT and distributed commit
ROLLBACK TO a savepoint undoes later work without necessarily ending the whole transaction. A savepoint is not a commit. Two-phase commit coordinates an outcome across participants; two-phase locking controls concurrent access. 2PC and 2PL solve different problems.
Worked exam problem
T1 writes X. T2 reads that X and commits. T1 then aborts. Is the schedule recoverable?
- T2 read uncommitted data written by T1: a dirty read.
- T2 committed before the transaction it depended on completed successfully. The schedule is not recoverable.
- If T2 waited to commit until after T1 committed, it could be recoverable. If T2 waited even to read X until T1 committed, the read would avoid a cascading rollback dependency.
- Strict schedules
- Cascadeless schedules
- Recoverable schedules
Practical example
A transaction inserts an order, makes a savepoint, then tries an optional discount update. If that update fails, a rollback to the savepoint can keep the earlier order pending. It is not permanent until the final commit.
BEGIN;
UPDATE Accounts SET balance = balance - 100 WHERE id = 1;
UPDATE Accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;Common exam traps
- A savepoint is not a backup and does not survive as a committed recovery point.
- COMMIT is not an ordinary undo button; recovery after commit needs a separate planned action.
- The short transfer example omits production checks such as sufficient funds, affected rows and retry handling.
Verified previous-year questions
GATE questions, paraphrased for clarity and checked against official answer keys. These are not IBPS past-paper claims. MSQ means more than one option may be correct.
Exam practice: apply the rules
Six original questions with plausible alternatives and worked explanations. These are practice questions, not previous-year questions.
Current usage and product differences
Cloud databases still need explicit transaction design. Serializable conflicts and deadlocks may require the application to retry the whole unit safely. External effects such as sending an email are not automatically rolled back with database rows.
References
Technical reference · Database System Concepts: chapter references