I am using SQL Server 2008.
What is the default lock behaviour with
UPDATE?NOLOCK?ROWLOCK?PAGLOCK?
How can I tell what the current level of lock is for a table?
Thanks, Bruce
|
I am using SQL Server 2008.
Thanks, Bruce |
||||
|
The default behavior for update is to first take a row-level update (U) lock to read the data, followed by an exclusive (X) lock to write it. You can see the current lock status of all objects in your DB by running "exec sp_lock". |
|||
|
|
|
It really depends on how much you're updating. Locks will escalate as the size of the query increases. If many rows within the same page will be modified, SQL Server will escalate to a |
|||||||||
|
UPDATE, SQL Server must take first anUPDATE(U) lock (while reading the existing data), which then needs to be escalated to an exclusive lock (X) on that row. This is the default behavior for a single update - if you're batch updating, your row locks might get escalated to table-level locks – marc_s Dec 14 '11 at 20:41