mysql 判断指定数据库指定表/一个表是否存在

前端之家收集整理的这篇文章主要介绍了mysql 判断指定数据库指定表/一个表是否存在前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

判断MysqL表是否存在四种方法

1. 通过information_schema

判断一个表是否存在

SELECT table_name FROM information_schema.TABLES WHERE table_name ='yourname';

指定数据库指定表是否存在

SELECT table_name FROM information_schema.TABLES WHERE  table_schema='dbname' and table_name ='yourname';

2. show tables

SHOW TABLES LIKE 'table_mode'

3. 在建表时不确定表是否存在

--格式
CREATE TABLE IF NOT EXISTS [Table Definition];
 
--示例
CREATE TABLE IF NOT EXISTS student(id int unsigned not null primary key,name varchar(32) not null)


猜你在找的MongoDB相关文章