USE

更新时间:
复制 MD 格式

USE specifies the database for the current session. After the database is specified, you can perform subsequent operations such as creating tables or running queries.

Syntax

USE [<catalog_name>.]<db_name>;

Parameters

Parameter

Required

Description

catalog_name

No

The catalog name.

  • If this parameter is not specified:

    • If no catalog is specified for the current session, the database under the adb catalog is used by default.

    • If a catalog is already specified for the current session, the database under that catalog is used.

  • To use a database under an External Catalog, you must specify this parameter.

  • To switch from a database under one catalog to a database under another catalog, you must specify this parameter.

This parameter is supported since version 3.2.7.

db_name

Yes

The database name. The database must exist.

Examples

Example 1: Use the example_db database under the adb catalog as the session database.

USE adb.example_db;

Or

USE example_db;

Example 2: Use the example_db database under the paimon_catalog catalog as the session database.

USE paimon_catalog.example_db;

Example 3: Switch the session database from paimon_catalog.example_db1 to iceberg_catalog.example_db2.

USE iceberg_catalog.example_db2;

Usage notes

  • USE takes effect only for the current session and does not affect other connections.

  • The syntax for specifying catalog_name is supported since AnalyticDB for MySQL 3.2.7.

  • Regardless of the active catalog, you can always query across catalogs using the three-part name <catalog>.<database>.<table>.

Related documents