SHOW TABLESSHOW TABLES

返回选择性指定的数据库的所有表。Returns all the tables for an optionally specified database. 此外,此语句的输出可以通过可选的匹配模式进行筛选。Additionally, the output of this statement may be filtered by an optional matching pattern. 如果未指定数据库,则从当前数据库返回表。If no database is specified then the tables are returned from the current database.

语法Syntax

SHOW TABLES [ { FROM | IN } database_name ] [ LIKE regex_pattern ]

参数Parameters

  • { FROM | IN } database_name{ FROM | IN } database_name

    列出表的数据库名称。The database name from which tables are listed.

  • regex_patternregex_pattern

    用于筛选掉不需要的表的正则表达式模式。The regular expression pattern that is used to filter out unwanted tables.

    • *| 字符外,该模式的工作方式类似于正则表达式。Except for * and | character, the pattern works like a regular expression.
    • 只有 * 则匹配 0 个或多个字符,| 用于分隔多个不同的正则表达式,其中任何一个表达式都可以匹配。* alone matches 0 or more characters and | is used to separate multiple different regular expressions, any of which can match.
    • 在处理前,在输入模式中删除前导空格和尾随空格。The leading and trailing blanks are trimmed in the input pattern before processing. 模式匹配不区分大小写。The pattern match is case-insensitive.

示例Examples

-- List all tables in default database
SHOW TABLES;
+--------+---------+-----------+
|database|tableName|isTemporary|
+--------+---------+-----------+
| default|      sam|      false|
| default|     sam1|      false|
| default|      suj|      false|
+--------+---------+-----------+

-- List all tables from userdb database
SHOW TABLES FROM userdb;
+--------+---------+-----------+
|database|tableName|isTemporary|
+--------+---------+-----------+
|  userdb|    user1|      false|
|  userdb|    user2|      false|
+--------+---------+-----------+

-- List all tables in userdb database
SHOW TABLES IN userdb;
+--------+---------+-----------+
|database|tableName|isTemporary|
+--------+---------+-----------+
|  userdb|    user1|      false|
|  userdb|    user2|      false|
+--------+---------+-----------+

-- List all tables from default database matching the pattern `sam*`
SHOW TABLES FROM default LIKE 'sam*';
+--------+---------+-----------+
|database|tableName|isTemporary|
+--------+---------+-----------+
| default|      sam|      false|
| default|     sam1|      false|
+--------+---------+-----------+

-- List all tables matching the pattern `sam*|suj`
SHOW TABLES LIKE 'sam*|suj';
+--------+---------+-----------+
|database|tableName|isTemporary|
+--------+---------+-----------+
| default|      sam|      false|
| default|     sam1|      false|
| default|      suj|      false|
+--------+---------+-----------+