this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Friday, December 5, 2008

Get Current Identity Value In SQL

Table that contain auto increment field as their primary key, we won't provide that value at the time of insert of data. So after insertion done we need to know which value is assigned to our primary key.

So at the time of insertion we will provide some output parameter as 
@ID AS INT 

After insertion statement just write 

SET @ID = @@IDENTITY 
OR
SET @ID = SCOPE_IDENTITY()
OR
SET @ID = IDENT_CURRENT

above all returns value inserted into identity columns.

No comments: