在 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 次浏览

开启您的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.