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|
+--------+---------+-----------+