Bird
0
0

Given this sequence:

medium📝 query result Q5 of 15
SQL - Transactions and Data Integrity
Given this sequence:
BEGIN;
SAVEPOINT sp1;
INSERT INTO products VALUES (10, 'Table');
SAVEPOINT sp2;
INSERT INTO products VALUES (20, 'Chair');
ROLLBACK TO sp1;
COMMIT;

Which rows will be in products after commit?
ANo rows
BOnly (10, 'Table')
COnly (20, 'Chair')
DBoth (10, 'Table') and (20, 'Chair')
Step-by-Step Solution
Solution:
  1. Step 1: Track inserts and savepoints

    sp1 is set, then (10, 'Table') inserted, then sp2 set, then (20, 'Chair') inserted.
  2. Step 2: Rollback to sp1 effect

    Rollback to sp1 undoes all changes after sp1, including the insert of (20, 'Chair') and sp2.
  3. Step 3: Commit finalizes remaining changes

    Only (10, 'Table') remains and is committed.
  4. Final Answer:

    Only (10, 'Table') -> Option B
  5. Quick Check:

    Rollback to earlier savepoint removes later inserts [OK]
Quick Trick: Rollback to earlier savepoint removes all later changes [OK]
Common Mistakes:
  • Assuming rollback to sp1 keeps inserts after sp1
  • Confusing savepoint order
  • Thinking commit restores rolled back changes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes