SQL to check if database is empty (no tables)

前端 未结 11 1348
后悔当初
后悔当初 2021-02-14 04:59

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!

11条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-14 05:47

    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.

提交回复
热议问题