Wednesday, March 11, 2009

Identity after inserting

How is exactly to get the identity after inserting in MS SQL?
If the table u are inserting have identity set to YES.
Hence you can use this.
declare @theid as bigint
insert into tablename select myvalue1, myvalue2
set @theid=@@IDENTITY


So the new ID is kept in the variable @theid now.

Reference: here

No comments: