Thursday, April 26, 2007

Identity reset for SQL Server 2000

Have you ever wanted to delete all the data from the table just for testing purposes...

It usually takes me around 2 mins to delete the data and reset the identity..

Here is a handy script which would actually reset the seed back to 0

Delete FROM tableName;
DBCC CHECKIDENT('tabelName', RESEED, 0)

Be careful though when working with foreignkeys...

I usually drop all relationships while am testing a perticular table and once the data insertion part makes me happy, I put the relations back and test again...

makes deletions and resets eazier...

No comments: