SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Locking on update...inner join


Locking on update...inner join

Author
Message
david.alcock
david.alcock
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1765 Visits: 1204
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'
Vedran Kesegic
Vedran Kesegic
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2734 Visits: 1266
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

david.alcock
david.alcock
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1765 Visits: 1204
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'
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search