USE SCHEMA

适用于:勾选“是” Databricks SQL 勾选“是” Databricks Runtime 10.2 及更高版本

设置当前架构。 设置当前架构后,将从当前架构解析由 SQL 引用的对表、函数和视图等对象的非限定引用。 默认架构名称为 default

虽然使用 SCHEMADATABASE 是可互换的,但最好使用 SCHEMA

语法

USE [SCHEMA] schema_name

参数

  • schema_name

    要使用的架构的名称。 如果 schema_name 是限定的,则当前目录也将设置为指定的目录名称。 如果该架构不存在,则会引发异常。

示例

-- 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