All Products
Search
Document Center

ALTER DATABASE

Last Updated: Jun 18, 2021

Description

You can execute the ALTER DATABASE statement to modify the attributes of a database.

Syntax

alter_database_stmt:
        ALTER DATABASE [database_name] [SET] alter_specification_list;

alter_specification_list: 
    alter_specification [alter_specification ...]

alter_specification: 
    [DEFAULT] {CHARACTER SET | CHARSET} [=] charset_name
  | [DEFAULT] COLLATE [=] collation_name
  | REPLICA_NUM [=] int_num
  | PRIMARY_ZONE [=] zone_name
  | {READ ONLY | READ WRITE}
    | DEFAULT TABLEGROUP [=] {NULL | table_group_name}

Parameters

Parameter

Description

database_name

The name of the database for which you want to modify attributes. The current default database is modified if you leave this parameter empty.

CHARSET charset_name

The character set that you want to modify.

COLLATE collation_name

The collation.

REPLICA_NUM int_num

The number of replicas.

PRIMARY_ZONE zone_name

The primary zone.

READ ONLY | READ WRITE

The attribute of the database. Valid values: READ ONLY and READ WRITE.

DEFAULT TABLEGROUP table_group_name

The default table group of the database. A NULL value indicates that no default table group is specified for the database.

Examples

  • Execute the following statements to modify database test2. Set the character set to UTF8MB4 and the collation to UTF8MB4_BIN. Set the database attribute to READ WRITE.
OceanBase(admin@test)>alter database test2 DEFAULT CHARACTER SET UTF8MB4;
Query OK, 0 rows affected (0.03 sec)

OceanBase(admin@test)>alter database test2 DEFAULT COLLATE UTF8MB4_BIN;
Query OK, 0 rows affected (0.03 sec)

OceanBase(admin@test)>alter database test2 READ WRITE;
Query OK, 0 rows affected (0.02 sec)