USE SCHEMA
Applies to: Databricks SQL 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
-
Name of the schema to use. The schema must exist within the current catalog or the exception SCHEMA_NOT_FOUND is raised.
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