In this blog, I am going to discuss how to clean a table so that your table auto-generated primary key start from 1.
We can use TRUNCATE to drop your table and generate a fresh one. It will remove all your table data as well as your auto-generated primary key.
TRUNCATE TABLE NameOfYourTable
If your table has a foreign key relation, then you will be unable to use TRUNCATE command.
In that case, you can follow the below strategy:
- Delete all the data from the table.
- Run below command
reset primary keyTransact-SQL1DBCC CHECKIDENT ('YourTableName', RESEED, 1)
you can also check the current SEED of your table by below command.
check seed1DBCC CHECKIDENT ('YourTableName', RESEED, 0);