Is there a way to TRUNCATE most tables in a MySQL schema?

I believe you'll have to write a script in whatever language you like the most. You can get a list of the tables in the schema from the information_schema db, then iterate over them, truncating any that you feel like Query would be something like: SELECT table_name FROM information_schema. Tables WHERE table_schema = 'test' AND table_name NOT IN ('table1', 'table2') Edit : Here's an example using Perl: use strict; use warnings; use DBI; my $dbh = DBI->connect("some_dsn"); my $sth = $dbh->prepare(q{SELECT table_name FROM information_schema.

Tables WHERE table_schema = 'test' AND table_name NOT IN ('table1', 'table2')}); $sth->execute(); $sth->bind_columns(\my $table_name); while($sth->fetch) { $dbh->do(q{TRUNCATE TABLE } . $table_name) }.

I believe you'll have to write a script in whatever language you like the most. You can get a list of the tables in the schema from the information_schema db, then iterate over them, truncating any that you feel like. Query would be something like: SELECT table_name FROM information_schema.

Tables WHERE table_schema = 'test' AND table_name NOT IN ('table1', 'table2'); Edit: Here's an example using Perl: use strict; use warnings; use DBI; my $dbh = DBI->connect("some_dsn"); my $sth = $dbh->prepare(q{SELECT table_name FROM information_schema. Tables WHERE table_schema = 'test' AND table_name NOT IN ('table1', 'table2')}); $sth->execute(); $sth->bind_columns(\my $table_name); while($sth->fetch) { $dbh->do(q{TRUNCATE TABLE } . $table_name) }.

Interesting. How exactly do I iterate over them, though? – Monster Jun 1 '09 at 15:41.

Nix one-liner: for I in `mysql -e "show tables MY_DB" | grep -vE "(table1|table2)"`; do mysql -e"TRUNCATE ${i}" MY_DB; done.

SELECT table_name FROM information_schema. My $sth = $dbh->prepare(q{SELECT table_name FROM information_schema. While($sth->fetch) { $dbh->do(q{TRUNCATE TABLE } .

I believe you'll have to write a script in whatever language you like the most. You can get a list of the tables in the schema from the information_schema db, then iterate over them, truncating any that you feel like.

Another method could be that you copy those four tables in a new schema and then delete the original database schema.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions