Login
登录 注册 安全退出
当前位置: 首页 > 文档资讯 > 技术教程 > 在 MySQL 中使用 SELECT 语句获取表名?

在 MySQL 中使用 SELECT 语句获取表名?

时间:2023-09-11浏览: [ ]

要使用 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)
复制本文链接文章为作者独立观点不代表优设网立场,未经允许不得转载。