Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Locking on update...inner join Expand / Collapse
Author
Message
Posted Friday, July 12, 2013 7:36 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, April 07, 2014 3:56 AM
Points: 200, Visits: 778
Thought I would re-write as it didnt make sense to me!

When an update query is based on a join, so you use update [table] from [sub query] which is inner joined to the original table, could there be potential issues of locking/blocking on the table.

Just thinking that the query would lock the table, exclusively but would the lock then prevent the inner join further along?


'Only he who wanders finds new paths'
Post #1473019
Posted Saturday, July 13, 2013 5:09 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, February 21, 2014 4:34 PM
Points: 369, Visits: 1,197
Locks that are granted to your session can only potentially block other sessions, never your session (if blocked, you are always blocked by other session).
So, the answer is: no.
Join is used to find the rows needed to be updated and values to update to, but you always update single table.
Use sys.dm_tran_locks to view the locks granted to your session. After commit (or rollback) locks are released, so you might investigate locks inside explicit transaction, like this:

begin tran
update ...

select * from sys.dm_tran_locks
-- rollback



_____________________________________________________
Microsoft Certified Master: SQL Server 2008
XDetails Addin - for SQL Developers
blog.sqlxdetails.com - Transaction log myths
Post #1473328
Posted Monday, July 15, 2013 6:48 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, April 07, 2014 3:56 AM
Points: 200, Visits: 778
Thanks the reply and confirming my thoughts. I didnt think that would be the case but I'll always go on the 'never know until someone confirms'...thanks again.

'Only he who wanders finds new paths'
Post #1473627
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse