Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Applies to:
Databricks SQL
Databricks Runtime 10.4 LTS and above
Unity Catalog only
Sets the current catalog. After the current catalog is set, partially and unqualified identifiers for tables, functions, and views that are referenced by SQLs are resolved from the current catalog.
Setting the catalog also resets the current schema to default.
Syntax
{ USE | SET } CATALOG [ catalog_name | ' catalog_name ' ]
Parameter
-
Name of the catalog to use. If the catalog does not exist, a NO_SUCH_CATALOG_EXCEPTION iss thrown.
Examples
-- 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 database to `default`
> USE CATALOG some_cat;
> SELECT current_catalog(), current_database();
some_cat default
-- Setting the schema in the current 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