USE DATABASE¶

Specifies the active/current database for the session.

If a database and schema, also known as a namespace, are not specified for a user session, all objects reference in SQL statements or queries executed in the system must be fully-qualified (in the form of db_id.schema_id.object_id). Specifying a database and schema for a user session enables using unqualified object names in SQL statements and queries.

For more information about fully qualified object names, see Object Name Resolution.

See also:

CREATE DATABASE , ALTER DATABASE , DROP DATABASE , SHOW DATABASES

Syntax¶

USE [ DATABASE ] <name>
Copy

Parameters¶

name

Specifies the identifier for the database to use for the session. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive.

Usage Notes¶

  • The DATABASE keyword does not need to be specified.

  • USE DATABASE automatically specifies PUBLIC as the current schema, unless the PUBLIC schema doesn’t exist (e.g. it has been dropped). To specify a different schema for a session, use the USE SCHEMA command.

Examples¶

USE DATABASE mydb;
Copy