?
?
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
时间: 2024-10-20 08:33:16