Database Reference
In-Depth Information
Chapter 21
Causes and Solutions for Deadlocks
In the preceding chapter, I discussed how blocking works. Blocking is the primary cause of poor performance.
It can lead to a special situation referred to as a deadlock , which in turn means that deadlocks are fundamentally a
performance problem. When a deadlock occurs between two or more transactions, SQL Server allows one transaction
to complete and terminates the other transaction, rolling back the transaction. SQL Server then returns an error
to the corresponding application, notifying the user that he has been chosen as a deadlock victim. This leaves the
application with only two options: resubmit the transaction or apologize to the end user. To successfully complete
a transaction and avoid the apologies, it is important to understand what might cause a deadlock and the ways to
handle a deadlock.
In this chapter, I cover the following topics:
Deadlock fundamentals
Error handling to catch a deadlock
Ways to analyze the cause of a deadlock
Techniques to resolve a deadlock
Deadlock Fundamentals
A deadlock is a special blocking scenario in which two processes get blocked by each other. Each process, while
holding its own resources, attempts to access a resource that is locked by the other process. This will lead to a blocking
scenario known as a deadly embrace, as illustrated in Figure 21-1 .
 
Search WWH ::




Custom Search