What's the default lock granularity in SQL Server?

女生的网名这么多〃 提交于 2019-12-01 16:25:28

问题


I've thoroughly read MSDN about table hints and I don't seem to find the locking granularity default. Suppose I have the following query:

SELECT TOP (1) * FROM MyTable WITH (UPDLOCK, READPAST) ORDER BY SomeColumn ASC;

You see, I specified UPDLOCK and READPAST hints, but not any of granularity hints such as TABLOCK or ROWLOCK.

Which granularity lock level is used by default?


回答1:


There is no 'default'. The granularity (row, page, (partition | object)) is computed dynamically based on allowed options for the object (allow_page_locks/allow_row_locks), information about the operation intent (probe, scan, insert), the estimated size of the rowset and a number of other factors (isolation level, is filegroup read only etc). In most cases you will get row-level granularity for singleton operations and page-level granularity for scans. The query you posted is probably going to go with page-level granularity because is a scan.



来源:https://stackoverflow.com/questions/13934472/whats-the-default-lock-granularity-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!