Bird
0
0

Consider the following SQL transaction sequence:

medium📝 query result Q13 of 15
SQL - Transactions and Data Integrity
Consider the following SQL transaction sequence:
BEGIN TRANSACTION;
INSERT INTO accounts VALUES (1, 100);
SAVEPOINT sp1;
UPDATE accounts SET balance = balance - 50 WHERE id = 1;
ROLLBACK TO SAVEPOINT sp1;
COMMIT;

What will be the final balance for account with id = 1?
A50
B100
C0
DRollback error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the transaction steps

    Insert sets balance to 100, then savepoint sp1 is created. The update subtracts 50, making balance 50.
  2. Step 2: Apply ROLLBACK TO SAVEPOINT

    Rollback to sp1 undoes the update, restoring balance to 100 before commit.
  3. Final Answer:

    100 -> Option B
  4. Quick Check:

    Rollback to savepoint undoes changes after it [OK]
Quick Trick: Rollback to savepoint undoes changes after it [OK]
Common Mistakes:
  • Assuming rollback undoes entire transaction
  • Ignoring rollback and expecting updated balance
  • Confusing rollback with commit

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes