The information in this article applies to:
SUMMARYUPDATE and DELETE statements that require a table scan result in an exclusive lock held on the modified table. MORE INFORMATION
Page 103 the SQL Server "Troubleshooting Guide" states:
Updates and deletes that do not use an index to search for rows that require modifications also require an exclusive table lock. This lock is not generated as a result of page lock promotion, but rather an immediate exclusive table lock. Consider the following example from the pubs database:
The results of the query show that a clustered index on au_id can be used to satisfy the search for a row to update:
Since the clustered index is used, only exclusive page locks are necessary for a consistent transaction. The output from running the sp_lock command with this transaction active is as follows:
NOTE: An exclusive intent lock is held on the table to prevent another exclusive table lock. However, if the table authors has no index that can be used for au_id, then the same query will require a table scan:
The query in this example requires an exclusive table lock on authors, because the server must perform a table scan to see which rows are required for modification. Because no index is available for au_id, the optimizer does not have any information to determine that only one row needs to be modified. The output from running the sp_lock command with this transaction active is as follows:
To avoid an exclusive table lock in this type of scenario, proper index design should be evaluated similar to considerations for SELECT queries. If the column modified in the SET clause is the same as the one used for searching, the performance trade offs associated with maintenance of the index must be evaluated with concurrency benefits. Statements other than updates and deletes can also require exclusive or shared table locks. The following table is a summary of locking behavior for INSERT, SELECT, UPDATE, DELETE, and other Transact-SQL statements for SQL Server. The table also contains information about which lock types are allowed concurrently between transactions and information about lock promotions.
Lock Types
Lock Promotion: Server will try to satisfy requests with page locks first. During a transaction, if more than 200 page locks per SDES are held, it will escalate to a Shared or Exclusive table lock instead, which lowers lock overhead. This table can also be found on the Microsoft TechNet CD under the title "Summary of Locks on SQL Server." REFERENCESFor additional information regarding concurrency and locking topics, please see the following articles in the Microsoft Knowledge Base:Q75722 INF: Reducing Lock Contention in SQL Server Q122485 INF: Identifying SPID Responsible for Lock Chain Q45542 INF: Shared Access to Modified Data Q43199 INF: Concurrency and Consistency and SQL Server Alternatives Additional query words: Windows NT
Keywords : kbprg SSrvLock SQLFAQ SSrvWinNT |
Last Reviewed: October 22, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |