Hi,
I am trying to make sure that two transactions running the below SP would not pick up the same SequenceId. Can this be achieved using the code below? Would "serializable" isolation level be the minimum to achive this?
Thanks.
CREATE PROCEDURE spSequenceNext
@sequenceid INT
AS
SET TRANSACTION ISOLATION SERIALIZABLE
SET NOCOUNT ON
UPDATE dbo.sequence
SET SequenceNbr = SequenceNbr + 1
WHERE SequenceId = @sequenceid
IF ROWCOUNT = 0
BEGIN
INSERT INTO Sequence
(SequenceId,
SequnceNbr)
VALUES
(@sequenceid,
0)
END
SELECT SequenceNbr
FROM dbo.Sequence
WHERE SequenceId = @sequenceid
GO