8
很简单的问题。在SQL 2008中,如果我有一个存储过程(请参阅下文),是否存在前两条语句之间存在争用条件的风险,或者存储过程是否像事务一样对它所触及的事件进行锁定?存储过程是否锁定表/行?
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;
Declare @ServerUser varchar(50)
-- Find a Free record
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
输出语句需要设定之后要放在正确的语法 – 2010-10-01 18:10:01
我用你的第一个例子但是我得到了错误:'当我运行它时,你只能在READ COMMITTED或REPEATABLE READ隔离级别指定READPAST锁。 – 2010-10-01 18:14:29
啊好的,放下这个HOLDLOCK,然后 – gbn 2010-10-01 18:19:17