USE CATALOG
S’applique à : Databricks SQL Databricks Runtime 10.4 LTS et ultérieur Unity Catalog uniquement
Définit le catalogue actuel. Une fois le catalogue actuel défini, les identificateurs partiellement et non qualifiés pour les tables, les fonctions et les vues qui sont référencées par les SQL sont résolus à partir du catalogue actuel.
La définition du catalogue redéfinit également le schéma actuel sur default
.
Syntaxe
{ USE | SET } CATALOG [ catalog_name | ' catalog_name ' ]
Paramètre
-
Nom du catalogue à utiliser. Si le catalogue n’existe pas, une NO_SUCH_CATALOG_EXCEPTION est levée.
Exemples
-- 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