Bird
0
0

Find the mistake in this SQL transaction to avoid deadlocks:

medium📝 Debug Q7 of 15
SQL - Transactions and Data Integrity
Find the mistake in this SQL transaction to avoid deadlocks:
BEGIN TRANSACTION;
LOCK Table B;
LOCK Table A;
COMMIT;
AMissing ROLLBACK statement
BLocking tables in inconsistent order can cause deadlocks
CCOMMIT should come before LOCK statements
DBEGIN TRANSACTION is not needed
Step-by-Step Solution
Solution:
  1. Step 1: Analyze lock order

    Locking Table B before Table A may conflict with other transactions locking in opposite order.
  2. Step 2: Identify deadlock risk

    Inconsistent lock order can cause circular waits and deadlocks.
  3. Final Answer:

    Locking tables in inconsistent order can cause deadlocks -> Option B
  4. Quick Check:

    Inconsistent lock order = Deadlock risk [OK]
Quick Trick: Lock tables in consistent order to avoid deadlocks [OK]
Common Mistakes:
  • Thinking ROLLBACK is mandatory every time
  • Believing COMMIT must come before locks
  • Ignoring lock order importance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes