Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I clear a DB table and reset the autoincrementing primary key?

Status
Not open for further replies.

jwarmuth

IS-IT--Management
Sep 22, 2001
151
CA
I've been testing a new program, however I'm done a particular phase.

Now I would like to clear all the garbage test records out of my table and start fresh. I can clear all the records no problem with a delete * statement, however the primary key column does not reset, continueing to add new records with a row number starting after the last record inserted.

Simply put, how can I clear the primary key so when I insert new records, they start with an index of 0 again.


I cna't believe it's so hard with SQL 2000, I used to do this with one little command in My SQL. :/

Jeff W.
MCSE, CNE
 
use truncate table rather than delete -- this will reset all your pks.

Margaret
 
Is the primary key an identity column?

Is yes issue the truncate table command and it should reset itself to the default value.

Regards,
AA
 
In QA .. Truncate table <table name>

Also, to reset the Identity you can use DBCC CheckIdent(). Check in BOL for full syntax.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top