Skip to content
Advertisement

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!

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement