去年我问这个问题:What could be causing the primary key exception?
但是我在这个存储过程中还有另一个错误:随机我得
使用FORETIGN对象“FK_Sessions”INSERT EXCEPTION “会话”,列“id”。
CREATE PROCEDURE [dbo].[MyProcedure]
@sessionId varchar(512),
@variable varchar(350),
@value image
AS
BEGIN
BEGIN TRAN
DECLARE @result int = 0;
DECLARE @locked bit;
IF (SELECT COUNT(*) FROM Sessions WITH(ROWLOCK,HOLDLOCK) WHERE id = @sessionId) = 0
BEGIN
SET @result = -1;
END
ELSE BEGIN
DELETE Variables WITH(ROWLOCK,HOLDLOCK) WHERE sessionId = @sessionId AND variable = @variable
IF @value IS NOT NULL
BEGIN
INSERT Variables VALUES(@sessionId, @variable, @value, 0)
END
END
COMMIT TRAN
RETURN @result
END
有什么想法吗?再次感谢