顯示資料表SHOW 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.
    • * 單獨符合零或多個字元,並 | 用來分隔多個不同的正則運算式,其中任何一個都可以相符。* 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|
+--------+---------+-----------+