Let's say I have a simple stored procedure that looks like this (note: this is just an example, not a practical procedure):
CREATE PROCEDURE incrementCounter AS
DECLARE @current int
SET @current = (select CounterColumn from MyTable) + 1
UPDATE
MyTable
SET
CounterColumn = current
GO
We're assuming I have a table called 'myTable' that contains one row, with the 'CounterColumn' containing our current count.
Can this stored procedure be executed multiple times, at the same time?
i.e. is this possible:
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