Geetha
Geetha

Reputation: 199

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. Now i want to get the primary key value of last updated record.

Geetha

Upvotes: 0

Views: 983

Answers (1)

Khanzor
Khanzor

Reputation: 5000

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

Upvotes: 1

Related Questions