USE DATABASE¶

Specifies the active/current database for 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.

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