What is the main difference between Lock , Block and Deadlock in SQL Server ?
The Meaning of lock is :
Lock is a done by database when any connection access a same piece of data concurrently. One connection need to access Piece of data .
The Meaning of Block :
It occurs when two connections need access to same piece of data concurrently and the meanwhile another is blocked because at a particular time, only one connection can have access. SQL knows that once the blocking process finishes the resource will be available and so the blocked process will wait (until it times out), but it won’t be killed.
The Meaning of Deadlock :
Deadlock occurs when one connection is blocked and waiting for a second to complete its work, and this situation is again with another process as it waiting for first connection to release the lock. Hence deadlock occurs.
i have 2 processes. P1 & P2 trying to get to 2 resources R1 & R2.
P1 gets a lock on R1
P2 gets a lock on R2
P1 tries to get a lock on R2 but can’t because it is locked by P2
P2 tries to get a lock on R1 but can’t because it is locked by P1
in this point no process can finish because they are waiting on locked resources. they are deadlocked. One of them must be killed to allow either of them to finish.
2 thoughts on “LOCK vs Block vs Deadlock in SQL Server”
Wow… Such a simple and excellent answer
LikeLiked by 1 person
Thanks , and welcome in our community