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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Reset DB Tables After A Copy? 1

Status
Not open for further replies.

3dColor

Programmer
Jan 10, 2006
240
0
0
US
I am creating a new site that is using the same tables from another DB.

Once I have copied the old tables over to the new site's DB is there a way to delete all the data and start the rows over at 1 instead of a high number where the old DB left off?

I basically want the structure of the database and reset to zero data.

Dave
 
By start rows over, I assume you have auto increment rows in there.
Code:
DELETE FROM [TableName]

reset the increment count with
Code:
ALTER TABLE [TableName] AUTO_INCREMENT = 0


Keith
 
You might be best just copying over the structure of the tables rather than all the data and then deleting it all
 
Would copying just the structure reset the auto increment rows to 0?
 
I presume you want a new database with empty tables. Yes just creating the tables will set auto inc to 0.
 
Code:
TRUNCATE [TableName]
deletes all the data in [TableName] and sets the AUTO_INCREMENT value to zero and thus has the same effect as
Code:
DELETE FROM [TableName]
ALTER TABLE [TableName] AUTO_INCREMENT = 0
Needless to say you don't actually enter the [ and ] when using these statements.

Andrew
Hampshire, UK
 
Thanks towerbase the TRUNCATE TABLE xx; command worked perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top