MySQL 如何检测MySQL中是否存在表格?
要检测表格的存在性,可以使用INFORMATION_SCHEMA.TABLES的概念。以下是语法 –
select table_name from information_schema.tables
where table_schema=database()
and table_name=yourTableName;
为了理解上面的语法,让我们创建一个表格 –
mysql> create table DemoTable2032
-> (
-> ClientId int,
-> ClientName varchar(20),
-> ClientAge int,
-> ClientCountryName varchar(20)
-> );
Query OK, 0 rows affected (1.07 sec)
以下是在数据库中检测表格是否存在的查询语句 –
mysql> select table_name from information_schema.tables
-> where table_schema=database()
-> and table_name='DemoTable2032';
这将产生以下输出 –
+---------------+
| TABLE_NAME |
+---------------+
| demotable2032 |
+---------------+
1 row in set (0.00 sec)
阅读更多:MySQL 教程
极客教程