Thursday, December 5, 2013

How to get the identity of a row that was last inserted into a specific table in a SQL Server database.

Use the
IDENT_CURRENT
key word.
Here is the syntax: IDENT_CURRENT('stringTableName')

It could be used like this:

Declare @TestId int
set @TestId = IDENT_CURRENT('TestTable')

or it can be simply selected:
Select IDENT_CURRENT('TestTable')

Here is a link to Microsofts definition: IDENT_CURRENT