SQL Server Interview Question #154

How can deadlocks be prevented or reduced?

Transactions, Locking, Blocking & Deadlocks Senior Advanced

Detailed Explanation

Common techniques include accessing tables and rows in a consistent order, keeping transactions short, using appropriate indexes so fewer rows are touched, avoiding unnecessarily high isolation levels, and reducing transaction scope.

Applications should also be prepared to retry transactions that fail with deadlock error 1205 when the operation is safe to retry. Extended Events and deadlock graphs should be used to identify the exact resources and statements involved before redesigning the query or transaction.