SQL server

Reseed the identity and find identity inserted.

The identity column in a table is automatically maintained by SQL. There may be times when the current identity value needs to be checked, or is some cases reset (reseeded).  To do this use the DBCC checkident command. Click here to see the details.

For programming purposes, if you want to find out the identity value just inserted into your column (scope specific, not session), you can use SCOPE_IDENTITY(), for session specific, use @@IDENTITY.  From BOL: A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch. SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY are similar functions because they return values that are inserted into identity columns. Note that the functions are similar, and not the same. Click here to see the BOL link.


Thinking about someting? Leave a Reply...

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s