我使用最少的日志记录,通过两个并行运行的Execute SQL Tasks和以下形式的SQL将两个数据集插入到空堆表中。
INSERT INTO Table (TABLOCK) SELECT FROM ...作业暂停后,其中一个SQL任务成为死锁受害者。下面是死锁图的XML输出。
有人可以解释幕后发生的事情吗?
  <resource-list>
   <objectlock lockPartition="0" objid="1586156746" subresource="FULL" dbid="7" objectname="dbo.TargetTable" id="lock7374a00" mode="IX" associatedObjectId="1586156746">
    <owner-list>
     <owner id="process9609dc8" mode="Sch-S"/>
     <owner id="process9609dc8" mode="IX"/>
    </owner-list>
    <waiter-list>
     <waiter id="process5e13048" mode="X" requestType="convert"/>
    </waiter-list>
   </objectlock>
   <objectlock lockPartition="0" objid="1586156746" subresource="FULL" dbid="7" objectname="dbo.TargetTable" id="lock7374a00" mode="IX" associatedObjectId="1586156746">
    <owner-list>
     <owner id="process5e13048" mode="Sch-S"/>
     <owner id="process5e13048" mode="IX"/>
    </owner-list>
    <waiter-list>
     <waiter id="process9609dc8" mode="X" requestType="convert"/>
    </waiter-list>
   </objectlock>
  </resource-list>事情变得棘手得多,因为我发现在大多数情况下,两个Execute SQL Tasks可以成功并行运行。请尝试以下方法:
Create table dbo.TablockInsert (c1 int, c2 int, c3 int)
--then issue the script in two Execute Sql Task in parallel you won't fail:
insert into dbo.TablockInsert(TABLOCK) SELECT 1, 1, 1由于唯一的区别是SELECT ... FROM ...语句,看起来SELECT ... FROM ...语句可能对这里的锁定模式有影响?