【发布时间】:2015-04-04 03:36:11
【问题描述】:
我有以下插入语句:
INSERT INTO [User].User_Profile
(UniqueId, Username, EmailAddress,
Password, BirthDay, BirthMonth,
BirthYear, Age, AccountType, DateCreated,
DeletedDate, DeletedReason, ProfileStatus)
VALUES
(NEWID(), @Username, @EmailAddress,
@Password, @BirthDay, @BirthMonth,
@BirthYeat, @Age, 1, SYSDATETIME(),
null, null, 2)
SELECT @@IDENTITY
@@IDENTITY 为特定用户返回新插入的行 ID,但我需要在执行插入语句后返回 NEWID() 值,因为我需要此 NEWID() 用于网站内的其他功能,但我我不确定如何检索它,因为我的 SQL 技能不是很好,我希望有人能帮助我。
【问题讨论】:
-
使用 OUTPUT 子句
-
我还建议使用
SCOPE_IDENTITY()而不是其他任何东西来获取新插入的标识值。 See this blog post for an explanation as to WHY
标签: sql-server-2008 sql-insert