title: How is it I am getting deadlocks when inserting into two different tables?
body: <p>This is a DynamicsAX app, and I am seeing the following deadlock quite often nowadays. If I understand the output correctly, the INSERT into table CUSTTRANS is being blocked by the INSERT into table CUSTSETTLEMENT.  I checked both tables, neither have triggers, so I am unclear how one caused a deadlock with the other?  CUSTTRANS table does have change tracking enabled, but not CUSTSETTLEMENT.</p>
  
  <pre><code>&lt;event name="xml_deadlock_report" package="sqlserver" timestamp="2016-07-19T23:43:24.567Z"&gt;
    &lt;data name="xml_report"&gt;
      &lt;value&gt;
        &lt;deadlock&gt;
          &lt;victim-list&gt;
            &lt;victimProcess id="processb7c273c38" /&gt;
          &lt;/victim-list&gt;
          &lt;process-list&gt;
            &lt;process id="processb7c273c38" taskpriority="0" logused="9000" waitresource="KEY: 5:72057881131876352 (9006753b740b)" waittime="37640" ownerId="221473485" transactionname="user_transaction" lasttranstarted="2016-07-19T16:42:46.317" XDES="0xb7caa3078" lockMode="RangeS-S" schedulerid="6" kpid="1940" status="suspended" spid="122" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2016-07-19T16:42:46.760" lastbatchcompleted="2016-07-19T16:42:46.737" lastattention="2016-07-19T13:12:49.450" clientapp="Microsoft Dynamics AX" hostname="DW22" hostpid="3076" loginname="xxx" isolationlevel="read committed (2)" xactid="221473485" currentdb="5" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056"&gt;
              &lt;executionStack&gt;
                &lt;frame procname="adhoc" line="1" stmtstart="2872" sqlhandle="0x020000005b952a20985c14b98773bd4fb5fd593a90918fd00000000000000000000000000000000000000000"&gt;
  INSERT INTO CUSTTRANS (ACCOUNTNUM,TRANSDATE,VOUCHER,...,REPORTINGEXCHADJUSTMENTRE    &lt;/frame&gt;
                &lt;frame procname="unknown" line="1" sqlhandle="0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"&gt;
  unknown    &lt;/frame&gt;
              &lt;/executionStack&gt;
              &lt;inputbuf&gt;(@P1 nvarchar(21),@P2 datetime2...@P67 numeric(32,4)&lt;/inputbuf&gt;
            &lt;/process&gt;
            &lt;process id="process1d15b0cf8" taskpriority="0" logused="3009456" waitresource="KEY: 5:72057881131876352 (e7873f5a29fe)" waittime="3566" ownerId="221391316" transactionname="user_transaction" lasttranstarted="2016-07-19T16:38:55.940" XDES="0x21b5e31d8" lockMode="RangeI-N" schedulerid="3" kpid="6320" status="suspended" spid="62" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2016-07-19T16:43:20.997" lastbatchcompleted="2016-07-19T16:43:20.993" lastattention="2016-07-19T15:31:56.060" clientapp="Microsoft Dynamics AX" hostname="DW22" hostpid="3076" loginname="xxxxx" isolationlevel="read committed (2)" xactid="221391316" currentdb="5" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056"&gt;
              &lt;executionStack&gt;
                &lt;frame procname="adhoc" line="1" stmtstart="1262" sqlhandle="0x020000000af3f41be10a624051e59a5f47e43bd38431bc5f0000000000000000000000000000000000000000"&gt;
  INSERT INTO CUSTSETTLEMENT (TRANSRECID,TRANSDATE,OFFSETTRANSVOUCHER,...,RECID) VALUES (@P1,@P2,@P3...,@P40)    &lt;/frame&gt;
              &lt;/executionStack&gt;
              &lt;inputbuf&gt;
  (@P1 bigint,@P2 datetime2,@P3 nvarchar(21)...,@P40 bigint)INSERT INTO CUSTSETTLEMENT (TRANSRECID,TRANSDATE,OFFSETTRANSVOUCHER,...&lt;/inputbuf&gt;
            &lt;/process&gt;
          &lt;/process-list&gt;
          &lt;resource-list&gt;
            &lt;keylock hobtid="72057881131876352" dbid="5" objectname="MicrosoftDynamicsAX.dbo.CUSTSETTLEMENT" indexname="I_075TRANSINDEX" id="lock6d97d4380" mode="RangeX-X" associatedObjectId="72057881131876352"&gt;
              &lt;owner-list&gt;
                &lt;owner id="process1d15b0cf8" mode="RangeX-X" /&gt;
              &lt;/owner-list&gt;
              &lt;waiter-list&gt;
                &lt;waiter id="processb7c273c38" mode="RangeS-S" requestType="wait" /&gt;
              &lt;/waiter-list&gt;
            &lt;/keylock&gt;
            &lt;keylock hobtid="72057881131876352" dbid="5" objectname="MicrosoftDynamicsAX.dbo.CUSTSETTLEMENT" indexname="I_075TRANSINDEX" id="lock7102fa100" mode="RangeS-S" associatedObjectId="72057881131876352"&gt;
              &lt;owner-list&gt;
                &lt;owner id="processb7c273c38" mode="RangeS-S" /&gt;
              &lt;/owner-list&gt;
              &lt;waiter-list&gt;
                &lt;waiter id="process1d15b0cf8" mode="RangeI-N" requestType="wait" /&gt;
              &lt;/waiter-list&gt;
            &lt;/keylock&gt;
          &lt;/resource-list&gt;
        &lt;/deadlock&gt;
      &lt;/value&gt;
    &lt;/data&gt;
    &lt;action name="collect_system_time" package="package0"&gt;
      &lt;value&gt;2016-07-19T23:43:24.567Z&lt;/value&gt;
    &lt;/action&gt;
    &lt;action name="client_hostname" package="sqlserver"&gt;
      &lt;value /&gt;
    &lt;/action&gt;
    &lt;action name="context_info" package="sqlserver"&gt;
      &lt;value /&gt;
    &lt;/action&gt;
    &lt;action name="attach_activity_id_xfer" package="package0"&gt;
      &lt;value&gt;CE2E9A01-A31C-464F-9288-AC45C7927760-574&lt;/value&gt;
    &lt;/action&gt;
    &lt;action name="attach_activity_id" package="package0"&gt;
      &lt;value&gt;634B86DC-58AB-4870-9170-5575B9C12D0A-1&lt;/value&gt;
    &lt;/action&gt;
  &lt;/event&gt;
  </code></pre>