Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the ID of last updated Row in SQL Server 2008

I have a requirement such that I want to get the id of last updated row in a table and I want to use this id for some other operation.

I don't have column like UpdatedOn , so that I can refer that column.

So is there any function like scope_identity and @@identity(which gives me id of last inserted row id) for Update also.

Please help me out for the same.

like image 458
Brijraj Avatar asked Dec 06 '25 23:12

Brijraj


1 Answers

You can do something like this

declare @mytable as TABLE
    (
      Id int
    )

Update Table Set Name='Nitin'
OUTPUT INSERTED.Id into @mytable
 where LastName='Varpe'

 Select Id from @mytable
like image 167
Nitin Varpe Avatar answered Dec 09 '25 13:12

Nitin Varpe