How to get the last inserted record id from SQL Server

Akiii
Posted by Akiii under Sql Server category on | Points: 40 | Views : 14653
To get the last inserted record in a table :-

SELECT @@IDENTITY



SELECT IDENT_CURRENT('TableName')



Try running the above statements against any table, you will get the id of the last record inserted.


Thanks and Regards
Akiii

Comments or Responses

Posted by: Stewsterl on: 2/25/2013 Level:Starter | Status: [Member] | Points: 10
You can also get the ID of a record your inserting.

@iMySearchID int OUTPUT

SELECT @iMySearchID=SCOPE_IDENTITY()

Login to post response