Locking on update...inner join

  • 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

    from 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'

  • 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
  • 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'

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply