title: Insert and delete in a transaction always block the rows?
body: <p>I have this table:</p>
  
  <pre><code>TableAB
  {
      IDA;
      IDB;
  }
  </code></pre>
  
  <p>And I want to ensure that always I have the pair (ID1, ID2) and (ID2, ID1). So I am trying to use this to scripts:</p>
  
  <p>To insert:</p>
  
  <pre><code>begin tran
  insert into tablaAB (IDTablaA, IDTablaB) VALUES(1,2);
  insert into tablaAB (IDTablaA, IDTablaB) VALUES(2,1);
  commit
  </code></pre>
  
  <p>To delete:</p>
  
  <pre><code>begin tran
  delete tablaAB where IDTablaA = 1 and IDTablaB = 2
  delete tablaAB where IDTablaA = 2 and IDTablaB = 1;
  commit
  </code></pre>
  
  <p>I am using two instance of Microsoft Management Studio, to run both queries, and in most of the cases, it works, I get the two rows or any of them. But sometimes, I get only one of them.</p>
  
  <p>The steps are:</p>
  
  <ul>
  <li>run the query to delete (1,2).</li>
  <li>run the query to add (1,2).</li>
  </ul>
  
  <p>In most of the cases, it is block until the transaction to delete both rows finishes, but in some case it can pass to the next line, to insert the second row. If this happens, then I don't have a coherence data.</p>
  
  <p>But I don't know if it is because I make some mistakes in the test or in same rare cases the first query is not blocked as I expect.</p>
  
  <p>Really in all cases the first insert should be block if the first delete is done?</p>
  
  <p>The table is empty. So it seems that the row is blocked when I try to delete and it doesn't allow to insert the row, but I don't know if really can be some rare situations in which the row is not blocked.</p>
  
  <p>Thanks.</p>