如何获取更新行的PK_ID
UPDATE
[M_RATINGS]
SET
[RATING] = @rating
WHERE
[POST_ID] = @postId AND
[USER_ID] = @userId;
答案 0 :(得分:4)
使用OUTPUT子句http://msdn.microsoft.com/en-us/library/ms177564.aspx
DECLARE @MyTableVar table(
ID int NOT NULL
);
UPDATE
[M_RATINGS]
SET
[RATING] = @rating
OUTPUT INSERTED.YourPK_ID INTO @MyTableVar
WHERE
[POST_ID] = @postId AND
[USER_ID] = @userId;
来自@MyTableVar的SELECT *;