Categories:
DDL Commands

USE <object>

Specifies the role, warehouse, database, or schema to use for the current session:

  • The role for a session determines the objects that can be accessed in queries and other SQL statements executed in the session.
  • A warehouse is required for a session to execute queries and other DML statements, including loading/unloading data, in the session.
  • If a database or schema are not specified for a session, any objects referenced in queries and other SQL statements executed in the session must be fully-qualified with the database and schema, also known as the namespace, for the object.

Syntax

USE ROLE <name>

USE WAREHOUSE <name>

USE [ DATABASE ] <name>

USE [ SCHEMA ] [<db_name>.]<name>

For specific syntax, usage notes, and examples, see:

General Usage Notes

  • To see the current role, database, schema, and warehouse for the session, use the corresponding context functions. For example:

    SELECT CURRENT_ROLE(), CURRENT_WAREHOUSE(), CURRENT_DATABASE(), CURRENT_SCHEMA();
    
    +----------------+---------------------+--------------------+------------------+
    | CURRENT_ROLE() | CURRENT_WAREHOUSE() | CURRENT_DATABASE() | CURRENT_SCHEMA() |
    |----------------+---------------------+--------------------+------------------|
    | SYSADMIN       | MYWH                | MYTESTDB           | PUBLIC           |
    +----------------+---------------------+--------------------+------------------+
    

    For more details, see Context Functions.

Examples

Use a warehouse:

USE WAREHOUSE mywarehouse;

Use a schema with the fully-qualified name of the schema specified:

USE mytestdb.testschema;

Use a schema without the fully-qualified name of the schema specified (requires the database for the schema to already be in use for the session):

USE testschema;