What is a deadlock in SQL Server, and why does it happen?
Short answer
A deadlock happens when two or more transactions each hold a lock that the other transaction needs, creating a cycle where neither can move forward, so SQL Server must step in and end one of them so the other can continue.
Advertisement
AModel answer
A deadlock happens when two or more transactions each hold a lock that the other transaction needs, creating a cycle where neither can move forward, so SQL Server must step in and end one of them so the other can continue.
Example
-- Transaction 1 locks Row A, then wants Row B -- Transaction 2 locks Row B, then wants Row A -- Neither can proceed, so this is a deadlock
Real-world example
Two warehouse update jobs run at the same time, each locking a different product row before trying to update the other one, causing SQL Server to cancel one of them automatically to break the cycle.
Likely follow-ups
- Does a deadlock ever resolve itself without SQL Server intervening?
- Is a deadlock the same thing as normal blocking?
Related topics