CREATE TABLE dbo.CounterTable
(
Counter int IDENTITY(1,1) NOT NULL
)
GO
--Procedure which Inserts unique IDs in table and returns the New ID
GO
--Procedure which Inserts unique IDs in table and returns the New ID
CREATE PROCEDURE dbo.GetNextCounter
AS
BEGIN TRAN
DECLARE @Counter BIGINT
INSERT INTO dbo.CounterTable DEFAULT VALUES
SET @Counter = SCOPE_IDENTITY()
COMMIT
RETURN @Counter
GO
--Now Use the @Counter to give each user the Unique ID
DECLARE @Counter int
EXEC @Counter = dbo.GetNextCounter
SELECT @Counter
No comments:
Post a Comment