In this blog, I am going to discuss how to clean a table so that your table auto-generated primary key start from 1.

Technique 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.

 

Technique 2:

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:

  1.  Delete all the data from the table.
  2. Run below command

    you can also check the current SEED of your table by below command.

     
Categories: MSSQL

Leave a Reply

Your email address will not be published. Required fields are marked *