Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 update table with tablock

Author  Topic 

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2010-04-09 : 12:08:03
I saw this code:

update Table1 with (Tablock)
set ...
where ID = ...

Only a single record gets updated. Can anyone tell what difference, if any, the 'with (Tablock)' would make in this case?

I thought even if several records are being updated, all the records would be locked during the update in an all-or-nothing sense.

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-04-09 : 12:23:27
TABLOCK forces the query to acquire a TABLE LOCK directly rather than going through the usual process of lock escalation.



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2010-04-09 : 13:29:26
... then even if that update was in a bigger transaction, if only one record is being updated in Table1, there would be no point to the 'with (Tablock)'?
Go to Top of Page
   

- Advertisement -