USE SCHEMA

S’applique à :coche marquée oui Databricks SQL coche pour oui Databricks Runtime 10.4 LTS et versions ultérieures

Note

Cette page décrit la USE SCHEMA commande SQL, qui définit le schéma courant d’une session. Pour le USE SCHEMA privilège du catalogue Unity, dont les utilisateurs ont besoin pour interagir avec des objets dans un schéma, voir USE SCHEMA.

Définit le schéma actuel. Une fois le schéma actuel défini, les références non qualifiées à des objets (tables, fonctions, vues, etc.) auxquels du code SQL fait référence sont résolues à partir du schéma actuel. Le nom de schéma par défaut est default.

Bien que SCHEMA et DATABASE soient interchangeables, il est préférable d’utiliser SCHEMA.

Syntaxe

USE [SCHEMA] schema_name

Paramètre

  • schema_name

    Nom du schéma à utiliser. Le schéma doit exister dans le catalogue actuel ou l’exception SCHEMA_NOT_FOUND est levée.

Exemples

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