📣
TiDB Cloud Premium 开放公测中。为企业级工作负载提供无限扩展、即时弹性伸缩和高级安全保障。此页面由 AI 自动翻译,英文原文请见此处。

SHOW TABLES



列出当前数据库或指定数据库中的表。

另请参阅:system.tables

语法

SHOW [ FULL ] TABLES [ {FROM | IN} <database_name> ] [ HISTORY ] [ LIKE '<pattern>' | WHERE <expr> ]
参数描述
FULL列出结果并附带额外信息。更多详情请参见示例。
FROM / IN指定数据库。如果省略,该命令返回当前数据库中的结果。
HISTORY显示保留时间内(默认 24 小时)被删除表的时间戳。如果某个表尚未被删除,则 drop_time 的值为 NULL。
LIKE使用大小写敏感的模式匹配按名称过滤结果。
WHERE使用 WHERE 子句中的表达式过滤结果。

示例

以下示例列出当前数据库(默认)的所有表名:

SHOW TABLES; ┌───────────────────┐ │ Tables_in_default │ ├───────────────────┤ │ books │ │ mytable │ │ ontime │ │ products │ └───────────────────┘

以下示例列出所有表及其附加信息:

SHOW FULL TABLES; ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ tables │ table_type │ database │ catalog │ owner │ engine │ cluster_by │ create_time │ num_rows │ data_size │ data_compressed_size │ index_size │ ├──────────┼────────────┼──────────┼─────────┼──────────────────┼────────┼────────────┼────────────────────────────┼──────────────────┼──────────────────┼──────────────────────┼──────────────────┤ │ books │ BASE TABLE │ default │ default │ account_admin │ FUSE │ │ 2024-01-16 03:53:15.354132 │ 0 │ 0 │ 0 │ 0 │ │ mytable │ BASE TABLE │ default │ default │ account_admin │ FUSE │ │ 2024-01-16 03:53:27.968505 │ 0 │ 0 │ 0 │ 0 │ │ ontime │ BASE TABLE │ default │ default │ account_admin │ FUSE │ │ 2024-01-16 03:53:42.052399 │ 0 │ 0 │ 0 │ 0 │ │ products │ BASE TABLE │ default │ default │ account_admin │ FUSE │ │ 2024-01-16 03:54:00.883985 │ 0 │ 0 │ 0 │ 0 │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

以下示例演示了当存在可选参数 HISTORY 时,结果将包含已删除的表:

DROP TABLE products; SHOW TABLES; ┌───────────────────┐ │ Tables_in_default │ ├───────────────────┤ │ books │ │ mytable │ │ ontime │ └───────────────────┘ SHOW TABLES HISTORY; ┌────────────────────────────────────────────────┐ │ Tables_in_default │ drop_time │ ├───────────────────┼────────────────────────────┤ │ books │ NULL │ │ mytable │ NULL │ │ ontime │ NULL │ │ products │ 2024-01-16 03:55:47.900362 │ └────────────────────────────────────────────────┘

以下示例列出名称以字符串 "time" 结尾的表:

SHOW TABLES LIKE '%time'; ┌───────────────────┐ │ Tables_in_default │ ├───────────────────┤ │ ontime │ └───────────────────┘ -- CASE-SENSITIVE pattern matching. -- No results will be returned if you code the previous statement like this: SHOW TABLES LIKE '%TIME';

以下示例列出数据大小大于 1,000 字节的表:

SHOW TABLES WHERE data_size > 1000 ; ┌───────────────────┐ │ Tables_in_default │ ├───────────────────┤ │ ontime │ └───────────────────┘

文档内容是否有帮助?