SHOW TABLES

适用于:check marked yes Databricks SQL check marked yes Databricks Runtime

返回选择性指定的架构的所有表。 此外,此语句的输出可以通过可选的匹配模式进行筛选。 如果未指定架构,则从当前架构返回表。

语法

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

参数

  • schema_name

    指定要从中列出表的架构名称。 如果未提供,则使用当前架构。

  • regex_pattern

    用于筛选掉不需要的表的正则表达式模式。

    • *| 字符外,该模式的工作方式类似于正则表达式。
    • 只有 * 则匹配 0 个或多个字符,| 用于分隔多个不同的正则表达式,其中任何一个表达式都可以匹配。
    • 在处理前,在输入模式中删除前导空格和尾随空格。 模式匹配不区分大小写。

示例

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

-- List all tables from usersc schema
> SHOW TABLES FROM usersc;
 database tableName isTemporary
 -------- --------- -----------
   usersc     user1       false
   usersc     user2       false

-- List all tables in usersc schema
> SHOW TABLES IN usersc;
 database tableName isTemporary
 -------- --------- -----------
   usersc     user1       false
   usersc     user2       false

-- List all tables from default schema 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