title: Is this SQL Statement Safe for Concurrent Access?
body: <p>Is the SQL statement below 'safe' for concurrent access? At what point will <code>A</code> get locked? If it's just before the <code>INSERT</code> is there a chance that the first <code>@count</code> may be wrong?</p>
  
  <pre><code>BEGIN TRAN;
      SELECT @count = count(1) from A
      DELETE FROM A where x=z
      SELECT @newCount = count(1) from A
      SELECT @newCount - @count
  COMMIT TRAN;
  </code></pre>