USE CATALOG

适用于:勾选“是” Databricks SQL 勾选“是” Databricks Runtime 10.4 LTS 及更高版本 勾选“是” 仅 Unity Catalog

设置当前目录。 设置当前目录后,将从当前目录解析由 SQL 引用的部分和非限定标识符,例如表、函数和视图。

设置目录还会将当前架构重置为 default

语法

{ USE | SET } CATALOG [ catalog_name | ' catalog_name ' ]

参数

  • catalog_name

    要使用的目录的名称。 如果该目录不存在,则会引发异常。

示例

-- Use the 'hive_metastore' which exists.
> USE CATALOG hive_metastore;

> USE CATALOG 'hive_metastore';

-- Use the 'some_catalog' which doesn't exist
> USE CATALOG `some_catalog`;
  Error: Catalog 'some_catalog' not found;

-- Setting the catalog resets the datbase to `default`
> USE CATALOG some_cat;
> SELECT  current_catalog(), current_database();
  some_cat default

-- Setting the schema within the curret catalog
> USE DATABASE some_db;
> SELECT  current_catalog(), current_database();
  some_cat some_db

-- Resetting both catalog and schema
> USE DATABASE main.my_db;
> SELECT  current_catalog(), current_database();
  main my_db

-- Setting the catalog resets the database to `default` again
> USE CATALOG some_cat;
> SELECT  current_catalog(), current_database();
  some_cat default