USE CATALOG

Preview

Unity Catalog is in Public Preview. To participate in the preview, contact your Databricks representative.

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 database to default.

Since: Databricks Runtime 10.3

Syntax

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

Parameter

  • catalog_name

    Name of the catalog to use. If the database does not exist, an exception is thrown.

Examples

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

> USE CATALOG 'hive_metastore';

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

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

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

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

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