I have a need to generate a sequence number to be used as a primary key (in a legacy system)
I want to know if the following solution suffers from concurrency during race conditions.
CREATE TABLE SequenceGenerator
(
Sequence INT
)
INSERT INTO SequenceGenerator SELECT 0
And here is the stored procedure that i will be calling whenever i need the next sequence number
CREATE PROCEDURE GetNextSequence
AS
SET NOCOUNT ON
DECLARE @NextSequence INT
UPDATE SequenceGenerator SET
@NextSequence = Sequence,
Sequence = Sequence + 1
RETURN @NextSequence + 1
Thanks
IDENTITYcolumns. And it would be helpful if you explain why you want to write your own code for this anyway?