U edizione Standard SCHEMA

Si applica a:segno di spunta sì Databricks SQL segno di spunta sì Databricks Runtime 10.4 LTS e versioni successive

Imposta lo schema corrente. Dopo aver impostato lo schema corrente, i riferimenti non qualificati a oggetti quali tabelle, funzioni e viste a cui viene fatto riferimento dagli sqls vengono risolti dallo schema corrente. Il nome dello schema predefinito è default.

Sebbene l'utilizzo di SCHEMA e DATABASE sia intercambiabile, SCHEMA è preferibile.

Sintassi

USE [SCHEMA] schema_name

Parametro

  • schema_name

    Nome dello schema da usare. Lo schema deve esistere all'interno del catalogo corrente o viene generata l'eccezione SCHEMA_NOT_FOUND .

Esempi

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