Is there a query (command) to truncate all the tables in a database in one operation? I want to know if I can do this with one single query.
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
Here is code snippet which I use to clear a table. Just change $conn info and TABLE_NAME.
--
David,
Thank you for taking the time to format the code, but this is how it is supposed to be applied.
-Kurt
On a UNIX or Linux box:
Make sure you are in a bash shell. These commands are to be run, from the command line as follows.
Note:
I store my credentials in my ~/.my.cnf file, so I don't need to supply them on the command line.
Note:
cpm is the database name
I am only showing a small sample of the results, from each command.
Find your foreign key constraints:
List the tables and row counts:
Truncate your tables:
Verify that it worked:
On a Windows box:
NOTE:
cpm is the database name
truncate multiple database tables on Mysql instance
Use Query Result to truncate tables
Note: may be you will get this error:
That happens if there are tables with foreign keys references to the table you are trying to drop/truncate.
Before truncating tables All you need to do is:
Truncate your tables and change it back to
Use this and form the query
Now use this to use this query
if you get an error like this
the easiest way to go through is at the top of your file add this line
which says that we don't want to check the foreign key constraints while going through this file.
It will truncate all tables in databases db1 and bd2.
Drop (i.e. remove tables)
Truncate (i.e. empty tables)