title: How to solve insert/delete deadlock on non-clustered index?
body: <p>I got a deadlock problem and I found that it's caused by two stored procedures that is called by different threads (2 called web services).</p>
  
  <ol>
  <li><strong>Insert sp</strong> that insert data in X table.</li>
  <li><strong>Delete sp</strong> that delete data in X table.</li>
  </ol>
  
  <p>Moreover, I got result that told me about deadlock happened in non-unique and non-clustered index of X table. Do you have any idea for solve this problem?</p>
  
  <p><strong>Update</strong></p>
  
  <p>From <a href="http://rusanu.com/2009/05/16/readwrite-deadlock/" rel="nofollow noreferrer">Read/Write deadlock</a>, I think it error because of the following statements.</p>
  
  <ul>
  <li>In insert statement, it get id(clustered index) and then non-clustered index.</li>
  <li>In delete statment, it get non-clustered index before id.</li>
  </ul>
  
  <p>So, I need to select id for delete statment like the following statement.</p>
  
  <pre><code>SELECT id FROM X WITH(NOLOCK) WHERE [condition]
  </code></pre>
  
  <p>PS. Both stored procedures are called in transaction.</p>
  
  <p><strong>Thanks,</strong></p>