USE SCHEMA

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 10.4 LTS and above

Sets the current schema. After the current schema is set, unqualified references to objects such as tables, functions, and views that are referenced by SQLs are resolved from the current schema. The default schema name is default.

While usage of SCHEMA and DATABASE is interchangeable, SCHEMA is preferred.

Syntax

USE [SCHEMA] schema_name

Parameter

Examples

-- Use the 'userschema' which exists.
> USE SCHEMA userschema;

-- Use the 'userschema1' which doesn't exist
> USE SCHEMA userschema1;
  Error: Database 'userschema1' not found;

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

-- Setting the schema within the current catalog
> USE SCHEMA some_schem;
> SELECT current_catalog(), current_schema();
  some_cat some_schema

-- Resetting both catalog and schema
> USE CATALOG main;
> USE SCHEMA my_schema;
> SELECT current_catalog(), current_schema();
  main my_schema

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