title: Is T-SQL Stored Procedure Execution 'atomic'?
body: <p>Let's say I have a simple stored procedure that looks like this (note: this is just an example, not a practical procedure):</p>
  
  <pre><code>CREATE PROCEDURE incrementCounter AS
  
  DECLARE @current int
  SET @current = (select CounterColumn from MyTable) + 1
  
  UPDATE
      MyTable
  SET
      CounterColumn = current
  GO
  </code></pre>
  
  <p>We're assuming I have a table called 'myTable' that contains one row, with the 'CounterColumn' containing our current count.</p>
  
  <p>Can this stored procedure be executed multiple times, at the same time?  </p>
  
  <p>i.e. is this possible:</p>
  
  <p>I call 'incrementCounter' twice.  Call A gets to the point where it sets the 'current' variable (let's say it is 5).  Call B gets to the point where it sets the 'current' variable (which would also be 5).  Call A finishes executing, then Call B finishes.  In the end, the table should contain the value of 6, but instead contains 5 due to the overlap of execution</p>