8
Apr/100
Apr/100
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 .
435 views

(3 votes, average: 4.67 out of 5)