共用方式為


USE CATALOG

適用於:核取記號為「是」Databricks SQL 核取記號為「是」Databricks Runtime 10.4 LTS 和更新版本核取記號為「是」僅限 Unity 目錄

設定目前的目錄。 設定目前目錄之後,會從目前的目錄解析 SQL 所參考之數據表、函式和檢視的部分和未限定識別符。

設定目錄也會將目前的架構 default重設為 。

語法

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

參數

範例

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

> USE CATALOG 'hive_metastore';

-- Use a catalog given as a string variable
> DECLARE mycat = 'main';
> USE CATALOG IDENTIFIER(mycat);

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

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