开发者

How to get the last updated records primary key value (varchar)

I am using output inserted.PKfielName to get the varchar type primary key value of last inserted record.开发者_C百科 Now i want to get the primary key value of last updated record.

Geetha


You just use the INSERTED clause again, such as in this example:

CREATE TABLE #test (id UNIQUEIDENTIFIER DEFAULT NEWSEQUENTIALID(), name VARCHAR(20))

INSERT INTO #test (name) VALUES ('boo')
INSERT INTO #test (name) VALUES ('woh')

SELECT *
FROM #test

UPDATE #test
SET name = 'whoops'
OUTPUT INSERTED.Id AS 'updated_id'
WHERE name = 'boo'

DELETE #test
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜