Bird
0
0

You want to update two related tables atomically. Which sequence correctly uses BEGIN TRANSACTION to ensure both updates succeed or fail together?

hard📝 Application Q8 of 15
SQL - Transactions and Data Integrity
You want to update two related tables atomically. Which sequence correctly uses BEGIN TRANSACTION to ensure both updates succeed or fail together?
ABEGIN TRANSACTION; UPDATE table1 SET col=1; COMMIT; UPDATE table2 SET col=2;
BBEGIN TRANSACTION; UPDATE table1 SET col=1; UPDATE table2 SET col=2; COMMIT;
CUPDATE table1 SET col=1; BEGIN TRANSACTION; UPDATE table2 SET col=2; COMMIT;
DUPDATE table1 SET col=1; UPDATE table2 SET col=2; BEGIN TRANSACTION; COMMIT;
Step-by-Step Solution
Solution:
  1. Step 1: Understand atomic updates

    Both updates must be inside the same transaction block to succeed or fail together.
  2. Step 2: Check each option

    Only BEGIN TRANSACTION; UPDATE table1 SET col=1; UPDATE table2 SET col=2; COMMIT; wraps both updates between BEGIN TRANSACTION and COMMIT.
  3. Final Answer:

    BEGIN TRANSACTION; UPDATE table1 SET col=1; UPDATE table2 SET col=2; COMMIT; -> Option B
  4. Quick Check:

    Both updates inside transaction = atomicity [OK]
Quick Trick: Put all related updates inside one transaction block [OK]
Common Mistakes:
  • Starting transaction after first update
  • Committing before all updates finish

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes