EdanB EdanB - 1 year ago 103
MySQL Question

SQL to check if database is empty (no tables)

I need to check if a database is totally empty (no tables) using an SQL query. How can this be done?

Thanks for the help!

Answer Source
SELECT COUNT(DISTINCT `table_name`) FROM `information_schema`.`columns` WHERE `table_schema` = 'your_db_name'

will return the actual number of tables (or views) in your DB. If that number is 0, then there are no tables.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download