MySQL 判断数据库和数据表是否存在

MySQL 判断数据库和数据表是否存在


如何使用SQL查询语句,判断数据库和数据表是否存在?

1、判断数据库是否存在

查询SQL如下:

select * 
from information_schema.SCHEMATA 
where SCHEMA_NAME = '需要查找的数据库名'; 

 也可以模糊查询,SQL如下:

select * 
from information_schema.SCHEMATA 
where SCHEMA_NAME like '%需要查询的数据库名的部分名称%'; 

2、判断数据表是否存在

查询SQL如下:

select * 
from information_schema.TABLES 
where TABLE_NAME = '需要查询的数据表名';

也可以模糊查询,SQL如下:

select * 
from information_schema.TABLES 
where TABLE_NAME like '%需要查询的数据库名的部分名称%';

猜你喜欢

转载自www.cnblogs.com/miracle-luna/p/12059270.html