用于检查数据库是否为空的SQL(无表)

Eda*_*anB 8 mysql sql

我需要使用SQL查询检查数据库是否完全为空(没有表).如何才能做到这一点?

谢谢您的帮助!

lon*_*eck 14

select count(*)
  from information_schema.tables
 where table_type = 'BASE TABLE'
   and table_schema = 'your_database_name_here'
Run Code Online (Sandbox Code Playgroud)


Mif*_*Fox 12

SELECT COUNT(DISTINCT `table_name`) FROM `information_schema`.`columns` WHERE `table_schema` = 'your_db_name'
Run Code Online (Sandbox Code Playgroud)

将返回数据库中实际的表(或视图)数.如果该数字为0,则表没有表格.


Fer*_*ano 6

在MYSQL中:

use DATABASE;
show tables;
Run Code Online (Sandbox Code Playgroud)


小智 6

要获取 MySQL 中没有表的所有数据库的列表:

use information_schema

select schema_name from `schemata` s
  left join `tables` t on s.schema_name = t.table_schema
  where t.table_name is null
;
Run Code Online (Sandbox Code Playgroud)

干杯,基督徒