Bird
0
0

You want to prevent deadlocks in a system where multiple transactions update two tables, Orders and Customers. Which approach is best?

hard📝 Application Q15 of 15
SQL - Transactions and Data Integrity
You want to prevent deadlocks in a system where multiple transactions update two tables, Orders and Customers. Which approach is best?
AEnsure all transactions update <code>Customers</code> first, then <code>Orders</code>, and keep transactions short
BAllow transactions to update tables in any order but increase isolation level to SERIALIZABLE
CUse long transactions with many updates to reduce lock frequency
DDisable locking to speed up updates
Step-by-Step Solution
Solution:
  1. Step 1: Understand deadlock prevention principles

    Accessing resources in the same order and keeping transactions short reduces deadlocks.
  2. Step 2: Evaluate options for best practice

    Ensure all transactions update Customers first, then Orders, and keep transactions short enforces consistent order and short transactions, preventing deadlocks effectively.
  3. Step 3: Analyze other options

    Allow transactions to update tables in any order but increase isolation level to SERIALIZABLE may increase deadlocks; Use long transactions with many updates to reduce lock frequency lengthens locks; Disable locking to speed up updates is unsafe and invalid.
  4. Final Answer:

    Ensure all transactions update Customers first, then Orders, and keep transactions short -> Option A
  5. Quick Check:

    Consistent order + short transactions = Deadlock prevention [OK]
Quick Trick: Use same update order and short transactions to prevent deadlocks [OK]
Common Mistakes:
  • Increasing isolation level can cause more deadlocks
  • Long transactions hold locks longer, increasing deadlock risk
  • Disabling locking breaks data integrity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes