Bird
0
0

Consider this transaction:

medium📝 query result Q4 of 15
SQL - Transactions and Data Integrity
Consider this transaction:
BEGIN TRANSACTION;
INSERT INTO orders VALUES (1, 'Book');
SAVEPOINT sp1;
INSERT INTO orders VALUES (2, 'Pen');
ROLLBACK TO sp1;
COMMIT;

What rows will be in the orders table after commit?
AOnly the row with (2, 'Pen')
BOnly the row with (1, 'Book')
CNo rows, transaction rolled back completely
DBoth rows (1, 'Book') and (2, 'Pen')
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the transaction steps

    The first insert adds (1, 'Book'), then a savepoint sp1 is created. The second insert adds (2, 'Pen').
  2. Step 2: Understand rollback to savepoint effect

    ROLLBACK TO sp1 undoes changes after sp1, so the second insert is undone.
  3. Step 3: Commit finalizes remaining changes

    Only the first insert remains and is committed.
  4. Final Answer:

    Only the row with (1, 'Book') -> Option B
  5. Quick Check:

    Rollback to savepoint undoes later inserts [OK]
Quick Trick: Rollback to savepoint undoes changes after it, commit saves earlier ones [OK]
Common Mistakes:
  • Assuming rollback to savepoint undoes entire transaction
  • Thinking commit undoes rollback
  • Confusing which inserts remain after rollback

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes