SQL 多并发 多人取号,防止重复取号SQL 办法
BEGIN TRAN
SELECT * from 表明 WITH(HOLDLOCK)
UPDATE 表名 SET 值=1 WHERE 字段=@carrierNo;
COMMIT TRAN;
ALTER PROCEDURE 名称 @字段名称 int AS BEGIN DECLARE @num VARCHAR(80),@returnNumber VARCHAR(80); BEGIN TRAN SELECT @num=number FROM 表名 WITH(ROWLOCK,UPDLOCK) WHERE 字段=@ClearanceId AND ISNULL(状态,0)=0; UPDATE 表名 WITH(ROWLOCK,UPDLOCK) SET 状态=1 WHERE 字段=@字段名称 AND ISNULL(状态,0)=0; IF @@ROWCOUNT>0 BEGIN SET @returnNumber=@num END ELSE BEGIN SET @returnNumber=''; END; SELECT @returnNumber; COMMIT TRAN; END