How to reset the Primary Key Index Value on an SQL Table

I recently had to reset the Primary key (Integer, AutoIncrement) from a Table I removed all entries from.

You can use the DBCC CKECKIDENT Statement to achieve this.

Reset Primary Key Index on SQL Table

USE YourDatabase
DBCC CHECKIDENT('YourTable', RESEED, 0)

This would reset the next identity value to begin at 1.

If you are receiving the following error, you might have not switched to the correct Database before executing the Statement:

Msg 2501, Level 16, State 45, Line 1
Cannot find a table or object with the name "YourTable". Check the system catalog.

Make sure you are using the “USE YourDatabase” statement before executing the DBCC .

4 responses to How to reset the Primary Key Index Value on an SQL Table

Hi, in “wamp” (MySQL) it should be something like
ALTER TABLE MyTable AUTO_INCREMENT = ‘1’;
Don’t know if the management studio for MySQL comes with wamp, otherwise just download at mysql.org

Hope this helps

Leave a Reply