SQL Server锁说明
时间:2020-03-06 14:25:19 来源:igfitidea点击:
下面是SQL Server 2000打算支持的锁的列表。我对"意图"锁的实际含义有些困惑。我在网上四处张望,答案似乎有些晦涩难懂。
在得到我的特定问题的答案之后,我希望将此问题用作Wiki,以了解每种锁定的含义以及在何种情况下将获得该类型的锁定。
- 独家(X)
- 意向排他(IX)
- 与Intent Exclusive(SIX)共享
- 意向更新(IU)
- 更新意向独占(UIX)
- 共享意图更新(SIU)
- 架构稳定性(Sch-S)
- 批量更新(BU)
- 共享键范围和更新资源锁(RangeS_U)
- 插入键范围和空资源锁(RangeI_N)
- 排他键范围和排他资源锁(RangeX_X)
- 转换锁(RangeI_S,RangeI_U,RangeI_X,RangeX_S,RangeX_U)
解决方案
意向锁位于表级别,指示事务将适当的锁置于表中的某些行上。
这可以加快对需要在表级别上放置锁的事务的冲突检查。例如,需要在表上具有排他锁的事务可以在表级别检测到冲突("意图共享"锁将在那里),而不必为共享锁检查所有行(或者页)。
SQL Server MSDN页面有一个合理的解释:
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.
若要通过示例获取有关SQL Server中的隔离级别(包括锁)及其对数据库的影响的详细信息,请参考以下链接:
http://www.sqllion.com/2009/07/transaction-isolation-levels-in-sql-server/