OceanBase logo

OceanBase

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

Product Overview
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

OceanBase

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

Product Overview
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 - V4.2.2

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    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. V4.2.2
    iconOceanBase Database
    SQL - V 4.2.2
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • 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:2026-04-15 08:27:14  Updated
    Share
    What is on this page
    Considerations
    Modify the schema of a table
    Modify indexes
    Rename a table
    Modify the PRIMARY KEY and FOREIGN KEY constraints for a table
    Change the number of replicas of a table

    folded

    Share

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

    Considerations

    You cannot perform other DDL operations when you modify the primary key or column type of a table. Vice versa, you cannot modify the primary key or column type of a table when you perform other DDL operations.

    Modify the schema of a table

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

    • You can add columns except for a primary key column to a table. To add a primary key column, you can add a normal column and then add a primary key to the column. For more information, see Define column constraints.

      Example: Add a normal column.

      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
      
      obclient> ALTER TABLE test ADD c3 int;
      Query OK, 0 rows affected
      
      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
      
    • You can change the type of a column. OceanBase Database supports the conversion of column types.

      For more information about the rules for changing the data types of columns, see Column type change rules.

      The syntax is as follows:

      ALTER TABLE table_name MODIFY (column_name data_type);
      

      Here is an example:

      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
      
      obclient> ALTER TABLE test MODIFY (c2 VARCHAR(70));
      Query OK, 0 rows affected
      
      obclient> DESCRIBE test;
      +-------+--------------+------+-----+---------+-------+
      | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
      +-------+--------------+------+-----+---------+-------+
      | C1    | NUMBER(38)   | YES  | NULL | NULL    | NULL |
      | C2    | VARCHAR2(70) | YES  | NULL | NULL    | NULL |
      +-------+--------------+------+-----+---------+-------+
      2 rows in set
      
    • You can rename a column. Here is an example:

      obclient> ALTER TABLE test RENAME COLUMN c1 TO c;
      Query OK, 0 rows affected
      
      obclient> DESCRIBE test;
      +-------+--------------+------+-----+---------+-------+
      | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
      +-------+--------------+------+-----+---------+-------+
      | C     | NUMBER(38)   | YES  | NULL | NULL    | NULL  |
      | C2    | VARCHAR2(70) | YES  | NULL | NULL    | NULL  |
      +-------+--------------+------+-----+---------+-------+
      2 rows in set
      
    • You can change the default value of a column. Here is an example:

      obclient> ALTER TABLE test MODIFY c DEFAULT 1;
      Query OK, 0 rows affected
      
      obclient> DESCRIBE test;
      +-------+--------------+------+-----+---------+-------+
      | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
      +-------+--------------+------+-----+---------+-------+
      | C     | NUMBER(38)   | YES  | NULL | 1       | NULL  |
      | C2    | VARCHAR2(70) | YES  | NULL | NULL    | NULL  |
      +-------+--------------+------+-----+---------+-------+
      2 rows in set
      
    • You can modify the NOT NULL constraint on a column. Here is an example:

      obclient> DESCRIBE test;
      +-------+--------------+------+-----+---------+-------+
      | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
      +-------+--------------+------+-----+---------+-------+
      | C     | NUMBER(38)   | YES  | NULL | 1       | NULL  |
      | C2    | VARCHAR2(70) | YES  | NULL | NULL    | NULL  |
      +-------+--------------+------+-----+---------+-------+
      2 rows in set
      
      obclient> ALTER TABLE test MODIFY (c2 NOT NULL);
      Query OK, 0 rows affected
      
      obclient> DESCRIBE test;
      +-------+--------------+------+-----+---------+-------+
      | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
      +-------+--------------+------+-----+---------+-------+
      | C     | NUMBER(38)   | YES  | NULL | 1       | NULL  |
      | C2    | VARCHAR2(70) | NO   | NULL | NULL    | NULL  |
      +-------+--------------+------+-----+---------+-------+
      2 rows in set
      
    • You can delete columns except for the primary key column and indexed columns from a table. Here is an example:

      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
      
      obclient> ALTER TABLE test DROP COLUMN c2;
      Query OK, 0 rows affected
      
      obclient> DESCRIBE test;
      +-------+--------------+------+-----+---------+-------+
      | FIELD | TYPE         | NULL | KEY | DEFAULT | EXTRA |
      +-------+--------------+------+-----+---------+-------+
      | C1    | NUMBER(38)   | NO   | PRI | NULL    | NULL  |
      +-------+--------------+------+-----+---------+-------+
      1 rows in set
      

    Modify indexes

    After you create a table, you can create a unique index on the table. Here is an example:

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

    Rename a table

    You can rename an existing table.

    OceanBase Database allows you to rename a table. Here is an example:

    obclient> ALTER TABLE test RENAME TO t1;
    

    Or

    obclient> RENAME TABLE test TO t1;
    

    Modify the PRIMARY KEY and FOREIGN KEY constraints for a table

    After you create a table, you can modify the PRIMARY KEY and FOREIGN KEY constraints for the table. For more information, see Define column constraints.

    Change the number of replicas of a table

    After you create a table, you can change the number of replicas of the table.

    Example: Change the number of replicas of a table to 2.

    obclient> ALTER TABLE test SET REPLICA_NUM=2;
    Query OK, 0 rows affected
    

    Previous topic

    Query the definition of a table
    Last

    Next topic

    Empty a table
    Next
    What is on this page
    Considerations
    Modify the schema of a table
    Modify indexes
    Rename a table
    Modify the PRIMARY KEY and FOREIGN KEY constraints for a table
    Change the number of replicas of a table