Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Transaction Isolation - Part 2 [Shared Lock. Exclusive Lock]

 by Sivaraman Dhamodaran on Jan 31, 2012

In this blog we will have a look at what is shared lock and exclusive lock.
Comments: 0 Views: 405 Printable Version 

When reading or writing the data SQL Server applies the lock on an affected row. The locks are two types. One is shared lock other one is exclusive lock. A shared lock is used by the read operation and an exclusive lock is acquired by the update operation. When a update puts a exclusive lock, read operation won't happen on that row and read operation should wait till the update completes.

Have a look at the below picture:

Pic01.JPG 

The first portion of picture shows you an update in progress and it is not yet completed. The update operation applied an exclusive lock before starting the actual update the required row in discussion. And a read operation along the way is waiting, as it cannot able to acquire the shared lock on that row. The Excusive lock not only blocks the read operation, it will block next coming update operation (On the same row) also. That means, only one update operation can have the exclusive lock on a particular row.

 

The second portion shows that the update operation is completed and the exclusive lock is removed. At this stage either an next waiting update can acquire a excusive lock or a read operation can acquire a shared lock on the row. In our depiction, a read operation acquired a shared lock and started reading the data. In the default Isolation level (We will discuss the remaining later), an exclusive lock request by an update operation is not permitted when the row is already got a shared lock. Then why it is called shared lock. Well.

 

Now look at the third portion of the picture. There are three more read operations going on in the same row. It shows that all three read operation shared a single lock and that's why we call it as Shared Lock.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor

 Blogger's Profile
Age: Not Available
Location:
Title: Systems Engineer
Joined: Oct 21, 2010
Education: Masters Degree
 More Blogs from this Blogger
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
Header file inclusion techniques
View all »
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.