2. BACKGROUND
• Locks are used by SQL Server DB engine to protect a
resource from modification by concurrent
transactions simultaneously.
• Among many locks used by SQL Server Update lock
is one of the least understood locks.
• This lock is used by SQL Server Database Engine to
prevent a kind of deadlock which would have been
possible if update lock was not there.
2
3. WITH NO UPDATE LOCKS
• If Update lock was not there then a transaction
would acquire a shared lock before updating a
resource.
• As shared locks are compatible, another concurrent
transaction would also place a shared lock on the
same resource.
• Now to update the resource, first transaction will try
to convert the shared lock to an exclusive lock.
3
4. WITH NO UPDATE LOCKS
CONTINUED……
• But the first transaction will fail to acquire an exclusive
lock because of shared lock placed by second
transaction.
• Similarly if the second transaction tries to acquire an
exclusive lock on the same row , it will also fail because
of shared lock placed by the first transaction resulting in
deadlock.
• This scenario is possible in Repeatable Read and
Serialization Isolation.
4
5. WITH UPDATE LOCKS
• To overcome this kind of deadlock, SQL Server
introduced update lock which is not compatible with
other locks.
• Only one transaction can acquire an update lock at a time
on a resource.
• Now just before updating the resource , the update lock
is converted to an exclusive lock.
5