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 is 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 (in the form of db_name.schema_name.object_name). For more information about fully-qualified object names, see Object name resolution.

  • If a database is specified for a session but the schema is not specified for a session, any objects referenced in queries and other SQL statements executed in the session must be qualified with the schema for the object (in the form of schema_name.object_name).

  • If the database and schema are specified for a user session, unqualified object names are allowed in SQL statements and queries.

Syntax¶

USE ROLE <name>

USE WAREHOUSE <name>

USE [ DATABASE ] <name>

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

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

Usage notes¶

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

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

For more details, see Context functions.

Examples¶

Use a warehouse:

USE WAREHOUSE mywarehouse;
Copy

Use a schema:

USE mytestdb.testschema;
Copy