Concurent transactions with serializable isolation level

  • 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

  • Duplicate post. No replies to this thread please. Direct replies to:http://www.sqlservercentral.com/Forums/Topic771724-338-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply