开发者

Get last inserted UNIQUEIDENTIFIER in SQL Server 2000

The OUTPUT 开发者_StackOverflow中文版clause is compatible with SQL Server 2005 but not SQL Server 2000.

How do I convert this command to work in SQL Server 2000?

CREATE TABLE sample
(
 ID uniqueidentifier NOT NULL DEFAULT newid(),
 Title varchar(30) NOT NULL
)

INSERT INTO sample (Title)
OUTPUT INSERTED.ID
VALUES ('Test1')

I need the command to retrieve the ID since the INSERT command needs to be called from a stored procedure.

Thanks for any help!


DECLARE @uid uniqueidentifier 
SET @uid  = newid()

INSERT INTO sample (ID, Title)
VALUES (@uid,'Test1')

SELECT @uid AS ID
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜