Christian Biggins Design, Technology, SEO, General Ramblings. Something for everybody.

19Mar/080

DROP TABLE(S) ??

For those of you that have ever tried to put up with a less-than-efficient operations department or are on a hosting plan with one database and only have drop permissions within that one database, then you'll know that dropping a few hundred tables from within the database is a bit of a time consuming and somewhat boring process. Well, why not create a drop query with a query?


SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(CONCAT(' ', TABLE_NAME)) , ';' ) AS statement FROM information_schema.TABLES WHERE TABLE_SCHEMA LIKE '%databasename%';

That will return a big 'DROP TABLE' statement. It will probably need to be run several times as depending on how many tables you have, the query may cut off half way through a name as the GROUP_CONCAT max length by default is 1024 chars.

No related posts.

blog comments powered by Disqus