Tamer Youssef

Just another site

By - Tamer

Retrieving the ID of the last inserted record

When you add a new record to a SQL Server table that has an identity column, you usually want to read back the auto-generated ID, for example to use it as a foreign key in another table. If you use stored procedures this is easy to do: just use an output parameter that you set as follows: SET @NewID =