OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V2.2.77Enterprise Edition

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V2.2.77
    iconOceanBase Database
    SQL - V 2.2.77Enterprise Edition
    SQL
    KV
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Modify a table

    Last Updated:2023-08-18 09:26:34  Updated
    share
    What is on this page
    Add, modify, and delete a column
    Modify an index
    Rename a table
    Delete a table group
    Delete an external key

    folded

    share

    Modify a table

    After a table is created, you can use the ALTER TABLE statement to modify it.

    Add, modify, and delete a column

    OceanBase Database allows you to add a column to a table, modify the column and its attributes, and delete a column from a table.

    • You cannot add a primary key column to a table.

      • Example for adding a column to a table in MySQL mode:

        obclient> DESCRIBE test;
        +-------+-------------+------+-----+---------+-------+
        | Field | Type        | Null | Key | Default | Extra |
        +-------+-------------+------+-----+---------+-------+
        | c1    | int(11)     | NO   | PRI | NULL    |       |
        | c2    | varchar(50) | YES  |     | NULL    |       |
        +-------+-------------+------+-----+---------+-------+
        2 rows in set (0.01 sec)
        
        obclient> ALTER TABLE test ADD c3 int;
        Query OK, 0 rows affected (0.03 sec)
        
        obclient> DESCRIBE test;
        +-------+-------------+------+-----+---------+-------+
        | Field | Type        | Null | Key | Default | Extra |
        +-------+-------------+------+-----+---------+-------+
        | c1    | int(11)     | NO   | PRI | NULL    |       |
        | c2    | varchar(50) | YES  |     | NULL    |       |
        | c3    | int(11)     | YES  |     | NULL    |       |
        +-------+-------------+------+-----+---------+-------+
        3 rows in set (0.00 sec)
        
      • Example for adding a column to a table in Oracle mode:

        obclient> DESCRIBE test;
        +-------+--------------+------+-----+---------+-------+
        | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
        +-------+--------------+------+-----+---------+-------+
        | C1    | NUMBER(38)   | NO   | PRI | NULL    | NULL  |
        | C2    | VARCHAR2(50) | YES  | NULL | NULL    | NULL  |
        +-------+--------------+------+-----+---------+-------+
        2 rows in set (0.01 sec)
        
        obclient> ALTER TABLE test ADD c3 int;
        Query OK, 0 rows affected (0.03 sec)
        
        obclient> DESCRIBE test;
        +-------+--------------+------+-----+---------+-------+
        | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
        +-------+--------------+------+-----+---------+-------+
        | C1    | NUMBER(38)   | NO   | PRI | NULL    | NULL  |
        | C2    | VARCHAR2(50) | YES  | NULL | NULL    | NULL  |
        | C3    | NUMBER(38)   | YES  | NULL | NULL    | NULL  |
        +-------+--------------+------+-----+---------+-------+
        3 rows in set (0.00 sec)
        
    • The column attributes that you can modify include column name and data type.

      • Example for modifying a column in MySQL mode:

        obclient> DESCRIBE test;
        +-------+-------------+------+-----+---------+-------+
        | Field | Type        | Null | Key | Default | Extra |
        +-------+-------------+------+-----+---------+-------+
        | c1    | int(11)     | NO   | PRI | NULL    |       |
        | c2    | varchar(50) | YES  |     | NULL    |       |
        +-------+-------------+------+-----+---------+-------+
        2 rows in set (0.01 sec)
        
        obclient>ALTER TABLE test CHANGE COLUMN c2 c CHAR(60);
        Query OK, 0 rows affected (0.03 sec)
        
        obclient> DESCRIBE test;
        +-------+----------+------+-----+---------+-------+
        | Field | Type     | Null | Key | Default | Extra |
        +-------+----------+------+-----+---------+-------+
        | c1    | int(11)  | NO   | PRI | NULL    |       |
        | c      | char(60) | YES  |     | NULL    |       |
        +-------+----------+------+-----+---------+-------+
        2 rows in set (0.00 sec)
        
      • Example for modifying a column in Oracle mode:

        obclient> DESCRIBE test;
        +-------+--------------+------+-----+---------+-------+
        | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
        +-------+--------------+------+-----+---------+-------+
        | C1    | NUMBER(38)   | NO   | PRI | NULL    | NULL  |
        | C2    | VARCHAR2(50) | YES  | NULL | NULL    | NULL  |
        +-------+--------------+------+-----+---------+-------+
        2 rows in set (0.01 sec)
        
        obclient> ALTER TABLE test MODIFY COLUMN c2 CHAR(60);
        
    • You cannot delete a column that is a primary key or has an index on it.

      • Example for deleting a column from a table in MySQL mode:

        obclient> DESCRIBE test;
        +-------+----------+------+-----+---------+-------+
        | Field | Type     | Null | Key | Default | Extra |
        +-------+----------+------+-----+---------+-------+
        | c1    | int(11)  | NO   | PRI | NULL    |       |
        | c      | char(60) | YES  |     | NULL    |       |
        +-------+----------+------+-----+---------+-------+
        2 rows in set (0.00 sec)
        
        obclient> ALTER TABLE test DROP c;
        Query OK, 0 rows affected (0.04 sec)
        
        obclient> DESCRIBE test;
        +-------+---------+------+-----+---------+-------+
        | Field | Type    | Null | Key | Default | Extra |
        +-------+---------+------+-----+---------+-------+
        | c1    | int(11) | NO   | PRI | NULL    |       |
        +-------+---------+------+-----+---------+-------+
        1 row in set (0.01 sec)
        
      • Example for deleting a column from a table in Oracle mode:

        obclient> DESCRIBE test;
        +-------+--------------+------+-----+---------+-------+
        | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
        +-------+--------------+------+-----+---------+-------+
        | C1    | NUMBER(38)   | NO   | PRI | NULL    | NULL  |
        | C2    | VARCHAR2(50) | YES  | NULL | NULL    | NULL  |
        +-------+--------------+------+-----+---------+-------+
        2 rows in set (0.01 sec)
        
        obclient> ALTER TABLE test DROP COLUMN c2;
        Query OK, 0 rows affected (0.04 sec)
        
        obclient> DESCRIBE test;
        +-------+--------------+------+-----+---------+-------+
        | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
        +-------+--------------+------+-----+---------+-------+
        | C1    | NUMBER(38)   | NO   | PRI | NULL    | NULL  |
        +-------+--------------+------+-----+---------+-------+
        1 rows in set (0.00 sec)
        

    Modify an index

    • MySQL mode

      In MySQL mode, OceanBase Database allows you to create unique and normal indexes on a table and modify index attributes.

      • Create a unique index

        After you create a table, you can create an index on the table. If a primary key is specified when you create the table, OceanBase Database creates a unique index on the primary key column by default.

        Example for creating a unique column on a table in Oracle mode:

        obclient> CREATE TABLE test (c1 int PRIMARY KEY, c2 VARCHAR(50));
        Query OK, 0 rows affected (0.04 sec)
        
        obclient> ALTER TABLE test ADD UNIQUE INDEX index_name(c2);
        Query OK, 0 rows affected (0.53 sec)
        
      • Create a normal index

        In MySQL mode, OceanBase Database allows you to create multiple indexes at a time. You can use either the INDEX or the KEY clause.

        obclient> CREATE TABLE test (c1 int PRIMARY KEY, c2 VARCHAR(50));
        Query OK, 0 rows affected (0.04 sec)
        
        obclient> ALTER TABLE test ADD INDEX myidx(c1,c2);
        Query OK, 0 rows affected (0.55 sec)
        
      • Modify index attributes

        In MySQL mode, OceanBase Database can show or hide variables. Variables are shown by default. You can hide them as needed.

        Syntax:

        obclient> ALTER TABLE test ALTER INDEX myidx INVISIBLE;
        
    • Oracle mode

      In Oracle mode, OceanBase Database allows you to create a unique index for a non-partitioned table.

      Example:

      • Create a unique index

        obclient> CREATE TABLE test (c1 int PRIMARY KEY, c2 VARCHAR(50));
        Query OK, 0 rows affected (0.04 sec)
        
        obclient> ALTER TABLE test ADD UNIQUE(c2);
        

    Rename a table

    OceanBase allows you to rename an existing table in both MySQL and Oracle modes.

    Example:

    obclient> ALTER TABLE test RENAME TO t1;
    

    Delete a table group

    OceanBase Database allows you to delete a table group in MySQL mode.

    Example:

    obclient> ALTER TABLE test DROP TABLEGROUP grp1;
    

    For more information about table groups, see manage table groups.

    Delete an external key

    You can delete an external key in both MySQL and Oracle modes in OceanBase Database.

    • Example statement in MySQL mode:

      obclient> ALTER TABLE test DROP FOREIGN KEY fk_name;
      
    • Example statement in Oracle mode:

      obclient> ALTER TABLE test DROP CONSTRAINT fk_name;
      

    Previous topic

    View table definition
    Last

    Next topic

    Empty a table
    Next
    What is on this page
    Add, modify, and delete a column
    Modify an index
    Rename a table
    Delete a table group
    Delete an external key