Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


locking question


locking question

Author
Message
hi2u
hi2u
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 1245
Hello,

For this scenario :

update Table1 with (TABLOCK, XLOCK)
...


then a "INSTEAD OF TRIGGER" on Table1 update Table1 with other value

Does the trigger keep the initial (TABLOCK, XLOCK) or the lock is released and another one is made for the trigger?

Thanks
Bhuvnesh
Bhuvnesh
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2928 Visits: 4076
hi2u (11/19/2012)
Does the trigger keep the initial (TABLOCK, XLOCK) or the lock is released and another one is made for the trigger?Thanks
Yes to maintain the atomicity there will be seperate LOCK

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
hi2u
hi2u
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 1245
Thank you for the info
Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3042 Visits: 5478
Bhuvnesh (11/19/2012)
hi2u (11/19/2012)
Does the trigger keep the initial (TABLOCK, XLOCK) or the lock is released and another one is made for the trigger?Thanks
Yes to maintain the atomicity there will be seperate LOCK


What do you mean "by separate LOCK"?
Intial locks placed on a table for UPDATE will be there until transaction is committed. INSTEAD OF trigger fires before SQL performs any change (not even change logging), so the only thing I can see may happen is LOCK escalation to the higher level...

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47271 Visits: 44392
hi2u (11/19/2012)
Hello,

For this scenario :

update Table1 with (TABLOCK, XLOCK)
...


then a "INSTEAD OF TRIGGER" on Table1 update Table1 with other value

Does the trigger keep the initial (TABLOCK, XLOCK) or the lock is released and another one is made for the trigger?


The exclusive table lock will be held until the end of the execution of the trigger.

Triggers execute within the transactions that fire them, exclusive locks are held until the end of the transaction, hence that lock will be held for the duration of the trigger's execution.

btw, you could have just used the TABLOCKX hint, that does the same as those two combined.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


hi2u
hi2u
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 1245
Thank you for the clarification

GilaMonster (11/20/2012)

btw, you could have just used the TABLOCKX hint, that does the same as those two combined.


This thread showed me that i should not trust every forum post but i always thought this was not true because of this :
http://dbaspot.com/ms-sqlserver/140553-transaction-deadlock-tablelocks.html
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47271 Visits: 44392
hi2u (11/20/2012)
t i always thought this was not true because of this : http://dbaspot.com/ms-sqlserver/140553-transaction-deadlock-tablelocks.html


That thread's talking about SELECT and the locks it takes. You're talking about UPDATE. Very different locking behaviour in the default isolation level.

In read committed isolation (the default), shared locks taken by selects are released as soon as the statement completes (sometimes earlier), while the exclusive locks taken by insert, update and delete are held until the end of the transaction.

And yeah, unfortunately not everything posted in the forums is true. You have to consider the poster's history and check more than one source to be sure (or test if it's something testable).


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


hi2u
hi2u
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 1245
well i learned something today.

Thank you !
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