如何在 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)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP