1、判断数据库是否存在
select * from information_schema.SCHEMATA where SCHEMA_NAME='hatc3500'
也可以模糊查询,SQL如下:
select *
from information_schema.SCHEMATA
where SCHEMA_NAME like '%需要查询的数据库名的部分名称%';
2、判断表是否存在
select count(*) from information_schema.TABLES t where t.TABLE_SCHEMA ="数据库名" and t.TABLE_NAME ="数据库表名";
//查询的例子
select count(*) from information_schema.TABLES t where t.TABLE_SCHEMA='hatc3500' and t.TABLE_NAME='captest'