CREATE TABLE dbo.GlobalSequence
(
id INT IDENTITY(1, 1)
)
GO
CREATE PROC seq ( @id INT OUTPUT )
AS
BEGIN
BEGIN TRAN
DECLARE @NewSequenceValue TABLE ( ID INT );
INSERT INTO dbo.GlobalSequence
OUTPUT inserted.id
INTO @NewSequenceValue
DEFAULT VALUES
ROLLBACK TRAN
SELECT @id = id
FROM @NewSequenceValue
END
-- test
DECLARE @id INT
EXEC seq @id OUTPUT
SELECT @id