我有一个奇怪的锁定问题,需要你的帮助来了解发生了什么。
使用查询,我在Prod_DW数据库中连接几个表(EventTransaction,Contact,Event和Outbound),并将结果保存到CustomDataExtract数据库的表中。
查询是这样的:
SELECT Col1, Col2, .... INTO CustomDataExtract..A1345_Contact_15022503
FROM Prod_DW..EventTransaction with (nolock) join ....
查询中使用的Prod_DW中的所有表都带有(nolock)选项,但在运行上述查询时,我仍然看到其他连接在Prod_DW表上被阻止。我的期望是,因为我查询使用with(nolock),在查询运行期间,它不应该对prod_DW表进行任何阻塞锁定。你能不能对此有所了解,并告诉我为什么我仍然看到其他连接被阻止。
以下是查询运行期间的Lock XML:
<Database name="CustomDataExtract">
<Locks>
<Lock request_mode="S" request_status="GRANT" request_count="1" />
</Locks>
<Objects>
<Object name="(null)">
<Locks>
<Lock resource_type="DATABASE.BULKOP_BACKUP_DB" request_mode="NULL" request_status="GRANT" request_count="1" />
<Lock resource_type="DATABASE.BULKOP_BACKUP_LOG" request_mode="NULL" request_status="GRANT" request_count="1" />
<Lock resource_type="DATABASE.ENCRYPTION_SCAN" request_mode="S" request_status="GRANT" request_count="1" />
<Lock resource_type="PAGE" page_type="*" request_mode="X" request_status="GRANT" request_count="1" />
</Locks>
</Object>
<Object name="A1345_Contact_15022503" schema_name="dbo">
<Locks>
<Lock resource_type="ALLOCATION_UNIT.BULK_OPERATION_PAGE" request_mode="S" request_status="GRANT" request_count="1" />
<Lock resource_type="HOBT.BULK_OPERATION" request_mode="IX" request_status="GRANT" request_count="1" />
<Lock resource_type="METADATA.INDEXSTATS" request_mode="Sch-S" request_status="GRANT" request_count="1" />
<Lock resource_type="OBJECT" request_mode="BU" request_status="GRANT" request_count="1" />
<Lock resource_type="OBJECT" request_mode="X" request_status="GRANT" request_count="1" />
</Locks>
</Object>
</Objects>
</Database>
<Database name="Prod_DW">
<Locks>
<Lock request_mode="S" request_status="GRANT" request_count="1" />
</Locks>
<Objects>
<Object name="Contact" schema_name="dbo">
<Locks>
<Lock resource_type="OBJECT" request_mode="Sch-S" request_status="GRANT" request_count="9" />
</Locks>
</Object>
<Object name="Event" schema_name="dbo">
<Locks>
<Lock resource_type="OBJECT" request_mode="Sch-S" request_status="GRANT" request_count="1" />
</Locks>
</Object>
<Object name="EventTransaction" schema_name="dbo">
<Locks>
<Lock resource_type="OBJECT" request_mode="IS" request_status="GRANT" request_count="2" />
<Lock resource_type="OBJECT" request_mode="Sch-S" request_status="GRANT" request_count="8" />
<Lock resource_type="PAGE" page_type="*" index_name="ndx_EventTransaction" request_mode="S" request_status="GRANT" request_count="1" />
</Locks>
</Object>
<Object name="Outbound" schema_name="dbo">
<Locks>
<Lock resource_type="OBJECT" request_mode="Sch-S" request_status="GRANT" request_count="1" />
</Locks>
</Object>
</Objects>
</Database>
答案 0 :(得分:1)
即使使用nolock,也始终会发生模式锁定。请阅读本文,了解有关nolock期间发生的事情的更多信息。
http://www.mssqltips.com/sqlservertip/2470/understanding-the-sql-server-nolock-hint/