在 MySQL 中使用 SELECT 語句獲取表名?


要使用 SELECT 語句獲取表名,請使用 “information_schema.tables”。讓我們看一個示例,其中包含 3 個表的資料庫。利用 SELECT 語句獲取所有表名的語法。

SELECT Table_name as TablesName from information_schema.tables where table_schema = 'yourDatabaseName';

使用資料庫 “test”,並應用以上語法來獲取表名使用 SELECT

mysql> use test;
Database changed
mysql> SELECT Table_name as TablesName from information_schema.tables where table_schema = 'test';

三個表的名稱的輸出。

+--------------------+
| TablesName         |
+--------------------+
| destination        |
| myisamtoinnodbdemo |
| originaltable      |
+--------------------+
3 rows in set (0.00 sec)

更新日期:2019-07-30

逾 7000 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告