Ever tried to DROP multiple tables from a MySQL database which all start with a specific prefix? For example, a default Joomla install adds in a number of tables all beginning with a prefix JOS_, also whenever you configure MySQL to create your own site it is best practice to create ideally a new 3 letter prefix for your site database e.g. ABC_
Even using the GUI phpMyAdmin is a pain as you’d have to point and click each table and select the drop icon, fancy doing that 50 times??? You would have thought you could use a wildcard prefix and the sql DROP command e.g. DROP table WHERE table LIKE ‘JOS_%’
But NO, that doesn’t work. Instead it is a 2 step process, FIRST use a CONCAT command to generate a new DROP command. Within an sql interface execute the following command (feel free to copy it!)
SELECT CONCAT( ‘DROP TABLE ‘, GROUP_CONCAT(table_name) , ‘;’ ) AS statement FROM information_schema.tables WHERE table_name like ‘JOS_%’;
Oh yeah you MUST replace JOS_ in the command above with your prefix or suffix even (just move that % around!). Rememeber the above command doesn’t actually drop or delete anything, it just gives you a text output as thus…
DROP TABLE jos_banner,jos_bannerclient,jos_bannerfinish,jos_categories,jos_components, etc. etc.
Which you can now use to delete those pesky tables, copy the above output and simply execute it within an sql interface again. It’s this 2nd bit that actively deletes the tables!!!
BANG – job done! Any probs drop me a line.