📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

ALTER DATABASE



Changes the name of a database, or sets default storage options for a database.

Syntax

-- Rename a database ALTER DATABASE [ IF EXISTS ] <name> RENAME TO <new_db_name> -- Set default storage options ALTER DATABASE [ IF EXISTS ] <name> SET OPTIONS ( DEFAULT_STORAGE_CONNECTION = '<connection_name>' | DEFAULT_STORAGE_PATH = '<path>' )

Parameters

ParameterDescription
DEFAULT_STORAGE_CONNECTIONThe name of an existing connection (created via CREATE CONNECTION) to use as the default storage connection for tables in this database.
DEFAULT_STORAGE_PATHThe default storage path URI (e.g., s3://bucket/path/) for tables in this database. Must end with / and match the connection's storage type.

Examples

Rename a database

CREATE DATABASE LAKE;
SHOW DATABASES; +--------------------+ | Database | +--------------------+ | LAKE | | information_schema | | default | | system | +--------------------+
ALTER DATABASE `LAKE` RENAME TO `NEW_LAKE`;
SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | NEW_LAKE | | default | | system | +--------------------+

Set default storage options

ALTER DATABASE analytics SET OPTIONS ( DEFAULT_STORAGE_CONNECTION = 'my_s3', DEFAULT_STORAGE_PATH = 's3://mybucket/analytics_v2/' );

Tag Operations

Assigns or removes tags on a database. Tags must be created with CREATE TAG first. For full details, see SET TAG / UNSET TAG.

Syntax

ALTER DATABASE [ IF EXISTS ] <name> SET TAG <tag_name> = '<value>' [, <tag_name> = '<value>' ...] ALTER DATABASE [ IF EXISTS ] <name> UNSET TAG <tag_name> [, <tag_name> ...]

Examples

ALTER DATABASE mydb SET TAG env = 'prod', owner = 'team_a'; ALTER DATABASE mydb UNSET TAG env, owner;

Was this page helpful?