views:

40

answers:

3

Possible Duplicate:
Truncate all tables in a MySQL database in one command?

how to delete all the data from all tables in the database.

A: 

use like this,

TRUNCATE `table1`;
TRUNCATE `table2`;
TRUNCATE `table3`;
TRUNCATE `table4`;
Karthik
Thanks pal, but i got many tables, so i thought some way out to do it at once.
Yajuvendra
A: 

If you have scripted creation of empty tables, it may be faster to drop and recreate the database, depending on number of tables. It is less typing for sure :-) -

Miro A.
i tried it but the auto generated ids are not set to zero. they continue from the last id that was truncated.
Yajuvendra
Add this to your table creation script:ALTER TABLE tablename AUTO_INCREMENT = 1
Miro A.
+3  A: 

You have to do it in single statements. You could create a loop, assigning the next table name to a variable and then use dynamic sql to execute the TRUNCATE statement.

Ardman