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 question Expand / Collapse
Author
Message
Posted Monday, November 19, 2012 3:14 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 11:50 AM
Points: 21, Visits: 1,184
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
Post #1386601
Posted Monday, November 19, 2012 10:59 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 2:16 AM
Points: 2,840, Visits: 3,983
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
Post #1386685
Posted Tuesday, November 20, 2012 8:00 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 11:50 AM
Points: 21, Visits: 1,184
Thank you for the info
Post #1386932
Posted Tuesday, November 20, 2012 8:38 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, December 12, 2014 10:09 AM
Points: 2,876, Visits: 5,201
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1386957
Posted Tuesday, November 20, 2012 9:10 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:13 AM
Points: 40,609, Visits: 37,070
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 2008, MVP
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

Post #1386990
Posted Tuesday, November 20, 2012 10:44 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 11:50 AM
Points: 21, Visits: 1,184
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

Post #1387055
Posted Tuesday, November 20, 2012 11:19 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:13 AM
Points: 40,609, Visits: 37,070
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 2008, MVP
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

Post #1387075
Posted Tuesday, November 20, 2012 11:27 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 11:50 AM
Points: 21, Visits: 1,184
well i learned something today.

Thank you !
Post #1387078
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse