We recommend that you have JavaScript enabled to enjoy the awesomeness of this site!

  • The page you are on right now   ⟶
  • EM Articles   ⟶
  • Reset your primary key column (identity) in your MS SQL table

Reset your primary key column (identity) in your MS SQL table

I was working with a clients database earlier this morning, as they are in the process of cloning their primary web application for another client. Their internal DBA just took a backup of the database, and restored it to a new location. So as I was going through the database I realized that I would need to reset the primary keys for some of the tables in the database. I don't this very often, and I had to dive into my bag of script goodies to remember how to do this. So, I thought I would share:

DBCC CHECKIDENT('table_name', RESEED, 0)

Just replace the table_name with the actual name of the table in your database, and specify the number you want the primpary key (identity) to restart with, and BAM you are done.