Quite a simple question. In SQL 2008 if I have a stored procedure (see below) do I run the risk of a race condition between the first two statements or does the stored procedure put a lock on the things it touches like transactions do?
ALTER PROCEDURE [dbo].[usp_SetAssignedTo]
-- Add the parameters for the stored procedure here
@Server varchar(50),
@User varchar(50),
@UserPool varchar(50)
AS
BEGIN
SET NOCOUNT ON;
-- Find a Free record
Declare @ServerUser varchar(50)
(SELECT top 1 @ServerUser = UserName from ServerLoginUsers
where AssignedTo is null and [TsServer] = @Server)
--Set the free record to the user
Update ServerLoginUsers
set AssignedTo = @User, AssignedToDate = getdate(), SourcePool = @UserPool
where [TsServer] = @Server and UserName = @ServerUser
--report record back if it was updated. Null if it was not available.
select *
from ServerLoginUsers
where [TsServer] = @Server
and UserName = @ServerUser
and AssignedTo = @User
END