SQL Server locks explained

我与影子孤独终老i 提交于 2019-12-03 12:08:51

The SQL server MSDN page has a reasonable explanation:

An intent lock indicates that SQL Server wants to acquire a shared (S) lock or exclusive (X) lock on some of the resources lower down in the hierarchy. For example, a shared intent lock placed at the table level means that a transaction intends on placing shared (S) locks on pages or rows within that table. Setting an intent lock at the table level prevents another transaction from subsequently acquiring an exclusive (X) lock on the table containing that page. Intent locks improve performance because SQL Server examines intent locks only at the table level to determine if a transaction can safely acquire a lock on that table. This removes the requirement to examine every row or page lock on the table to determine if a transaction can lock the entire table.

The intent locks are placed on the table level and indicate that a transaction will place appropriate locks on some of the rows in the table.

This speeds up conflict checking for transactions that need to place locks on the table level. For example a transaction needing an exclusive lock on a table can detect the conflict at the table level (the "intent shared" lock will be there), instead of having to examine all of the rows (or pages) for shared locks.

Another important feature of the Intent locks is you don't place them from the code explicitly, they are requested implicitly when you place a non-intent lock.

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