SQL to check if database is empty (no tables)

前端 未结 11 1629
后悔当初
后悔当初 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:31

    Solution: In order to verify your databases is not empty you can watch list of tables and measure instances in it.

    first: perform simple connection to your db mysql -u -p ,run show databases; pick your database using use ; and then run show tables; and expect to have list of tables.

    +----------------------------------------+
    | Tables_in_databaseName                 |
    +----------------------------------------+
    | databaseA                              |
    | databaseB                              |
    | databaseC                              |
    +----------------------------------------+
    

    Second: Perform simple count action on primary key / main table on sql and count instances:

    select count(*) from ;
    

    count result should be > 0

    +----------+
    | count(*) |
    +----------+
    |   100    |
    +----------+
    

提交回复
热议问题