dbTalk Databases Forums  

atomicity of locking in select from multiple tables case

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss atomicity of locking in select from multiple tables case in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
migurus
 
Posts: n/a

Default atomicity of locking in select from multiple tables case - 10-13-2010 , 05:32 PM






SQL 2005, my connection is under default READ COMMITED level.

I'd like to know whether locks are placed atomically when I say:

select T1.Col1, T2.Col2 from TBL1 T1, TBL2 T2 where T1.Key=T2.Key
etc...

In other words, does db acquire locks for resources T1 and T2
atomically (all or none), or there is a possibility that it would
acquire lock on T1 resource and wait for T2 resource to become
available.

Thanks in advance.

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: atomicity of locking in select from multiple tables case - 10-14-2010 , 02:14 AM






migurus (migurus (AT) yahoo (DOT) com) writes:
Quote:
SQL 2005, my connection is under default READ COMMITED level.

I'd like to know whether locks are placed atomically when I say:

select T1.Col1, T2.Col2 from TBL1 T1, TBL2 T2 where T1.Key=T2.Key
etc...

In other words, does db acquire locks for resources T1 and T2
atomically (all or none), or there is a possibility that it would
acquire lock on T1 resource and wait for T2 resource to become
available.
First of all, SQL Server can lock on lower level than on the table level; by
default locks are on row level, but SQL Server can escalate to higher levels
if needed.

Locks are acquired and released as needed. That is, if you run:

SELECT * FROM tbl WHERE OrderID > 1000000 ORDER BY OrderID

and there is a clustered index on OrderID, SQL Server will lock the rows as
it reads them, and once a row has been passed to the client, the lock will
be released, even if SQL Server is still reading more rows. If towards the
end there is a row which is locked, the SELECT process will stall.
--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.