Deleting rows from a table with an Identity Column


If you delete all the records from a table it won’t reset the identity.

To reset the identity seed you need to use a DBCC command.

DELETE FROM myTableName
DBCC CHECKIDENT('myTableName', RESEED, 0)
// DBCC CHECKIDENT (table_name, RESEED, new_reseed_value)
Setting new_reseed_value to 0 will cause the next INSERT with an identity = 1
This T-SQL applies to MS SQL Server 2000+
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