Bird
0
0

Identify the error in the following transaction code:

medium📝 Debug Q14 of 15
SQL - Transactions and Data Integrity
Identify the error in the following transaction code:
BEGIN TRANSACTION;
SAVEPOINT sp1;
INSERT INTO orders VALUES (101, 'Book');
ROLLBACK TO sp2;
COMMIT;
AROLLBACK TO references a non-existent savepoint
BMissing COMMIT before SAVEPOINT
CSAVEPOINT must come after INSERT
DROLLBACK TO cannot be used inside transactions
Step-by-Step Solution
Solution:
  1. Step 1: Check savepoint names

    Only sp1 is created, but rollback tries to use sp2 which does not exist.
  2. Step 2: Validate transaction flow

    Rollback to a non-existent savepoint causes an error; other statements are valid.
  3. Final Answer:

    ROLLBACK TO references a non-existent savepoint -> Option A
  4. Quick Check:

    Rollback must use existing savepoint name [OK]
Quick Trick: Rollback must refer to an existing savepoint [OK]
Common Mistakes:
  • Using wrong savepoint name in rollback
  • Thinking savepoints must follow inserts
  • Believing rollback can't be inside transactions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes