Reset Identity Seed

DBCC CHECKIDENT ('[TestTable]', RESEED, 0)

from StackOverflow

This is useful for resetting the identity column if you ever make a mistake by inserting duplicated rows and end up deleting one of them. My use-case was that this identity column needs to be in-sync with the other databases and it is used as foreign keys in some other tables.

Alternatively, you can turn it off:

SET IDENTITY_INSERT sometableWithIdentity ON

INSERT sometableWithIdentity (IdentityColumn, col2, col3, ...)
VALUES (AnIdentityValue, col2value, col3value, ...)

SET IDENTITY_INSERT sometableWithIdentity OFF
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s