How to reset Identity Seed Column in SQL Server
It could’nt have got more difficult then this…..
Just got stuck with this very painful and mind blasting task. Well it may sound so stupid but sometimes the easisets of the things are ones you cannot answer. this evening I was working on a client database and after having deleted all the information from a table we wanted to repopulate it with a new set of data. The primary key was the all famous Identity seed. So that means inspite of deleting all the data it would start assiging the primary key number from where it had last stopped and not from 1 again.
So if you want to restart from 1, there are 2 approcahes to this:-
1. Instead of deleting table use truncate table which will delete all data and also reset the primary key.
2. but if you have already deleted the data then you can just use the DBCC CHECKIDENT(‘Customer’, RESEED, 0) command where Customer is table name.
Have a nice day
Nice post!
Flying Tech
CTEric
July 23, 2010 at 3:08 pm