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 - V4.2.1

    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. V4.2.1
    iconOceanBase Database
    SQL - V 4.2.1
    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

    Add tables to a table group

    Last Updated:2023-12-25 08:49:41  Updated
    share
    What is on this page
    Limitations
    Prerequisites
    Specify a table group while creating a table
    Add existing tables to a table group
    References

    folded

    share

    After you create a table group, you can add tables meeting specific conditions to the table group.

    Limitations

    During the upgrade of OceanBase Database, it is prohibited to use the ALTER TABLEGROUP statement to add tables to a table group.

    Prerequisites

    Before you add a table to a table group, view the attributes and the partition information about existing tables in the table group to verify whether the current table meets the conditions for joining the table group. For more information about how to view the information about a table group, see Query information about a table group.

    If you want to specify a table group when you create a table, make sure that the table meets the conditions for joining the table group.

    • A table group with the SHARDING attribute set to NONE has no limitations on the table to be added to the table group. Such a table group can contain non-partitioned tables, partitioned tables, and subpartitioned tables.

    • A table group with the SHARDING attribute set to PARTITION requires that the table to be added have the same partition definition as existing tables in the table group, including the partitioning type, partition count, and partition value. Such a table group can contain both partitioned tables and subpartitioned tables. The table group can also contain only non-partitioned tables.

      Specifically, the same partition definition means that:

      • Tables in the table group have the same partitioning type, such as RANGE partitioning.
      • HASH-partitioned tables have the same number of referenced columns and the same number of partitions.
      • RANGE-partitioned tables have the same number of referenced columns, the same number of partitions, and the same range definition.
    • A table group with the SHARDING attribute set to ADAPTIVE requires that the table to be added have the same partition definition and subpartition definition as existing tables in the table group, including the partitioning type, partition count, and partition value. The tables in the table group must be all partitioned tables or all subpartitioned tables. The table group can also contain only non-partitioned tables.

      Specifically, the same partition definition means that:

      • Tables in the table group have the same partitioning type such as HASH-RANGE partitioning.
      • HASH-partitioned tables have the same number of referenced columns and the same number of partitions.
      • RANGE-partitioned tables have the same number of referenced columns, the same number of partitions, and the same range definition.
      • The requirements on subpartitions are the same as those on partitions, depending on the partitioning type.

    Specify a table group while creating a table

    After you create a table group, you can specify this table group when you create a table. The syntax is as follows:

    CREATE TABLE table_name column_definition TABLEGROUP = table_name [partition_option];
    

    where

    • column_definition specifies the name and data type of the column in the table.

    • TABLEGROUP specifies the table group to which the table belongs.

    • partition_option specifies the partition information of the table.

    The following examples show how to create a table and add it to a table group:

    • Create a table and add it to a table group with the SHARDING attribute set to NONE.

      1. Create a table group named tblgroup1 and set the SHARDING attribute to NONE.

        CREATE TABLEGROUP tblgroup1 SHARDING = 'NONE';
        
      2. Create a non-partitioned table named tbl1 and add it to the tblgroup1 table group.

        CREATE TABLE tbl1 (col NUMBER) TABLEGROUP = tblgroup1;
        
      3. Create a partitioned table named tbl2 and add it to the tblgroup1 table group.

        CREATE TABLE tbl2(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup1
        PARTITION BY LIST(col1)
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
      4. View tables in the table group.

        SELECT * FROM SYS.DBA_OB_TABLEGROUP_TABLES WHERE tablegroup_name = 'TBLGROUP1';
        

        The result is as follows:

        +-----------------+-------+------------+----------+
        | TABLEGROUP_NAME | OWNER | TABLE_NAME | SHARDING |
        +-----------------+-------+------------+----------+
        | TBLGROUP1       | SYS   | TBL1       | NONE     |
        | TBLGROUP1       | SYS   | TBL2       | NONE     |
        +-----------------+-------+------------+----------+
        2 rows in set
        
    • Create a table and add it to a table group with the SHARDING attribute set to PARTITION.

      1. Create a table group named tblgroup2 and set the SHARDING attribute to PARTITION.

        CREATE TABLEGROUP tblgroup2 SHARDING = 'PARTITION';
        
      2. Create a partitioned table named tbl3 and add it to the tblgroup2 table group.

        CREATE TABLE tbl3(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup2
        PARTITION BY LIST(col1)
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
      3. Create a table named tbl4 that has the same partitioning type, partition count, and partition value as the table tbl3, and add the created table to the tblgroup2 table group.

        CREATE TABLE tbl4(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup2
        PARTITION BY LIST(col1)
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
      4. View tables in the table group.

        SELECT * FROM SYS.DBA_OB_TABLEGROUP_TABLES WHERE tablegroup_name = 'TBLGROUP2';
        

        The result is as follows:

        +-----------------+-------+------------+-----------+
        | TABLEGROUP_NAME | OWNER | TABLE_NAME | SHARDING  |
        +-----------------+-------+------------+-----------+
        | TBLGROUP2       | SYS   | TBL3       | PARTITION |
        | TBLGROUP2       | SYS   | TBL4       | PARTITION |
        +-----------------+-------+------------+-----------+
        2 rows in set
        
    • Create a table and add it to a table group with the SHARDING attribute set to ADAPTIVE.

      1. Create a table group named tblgroup3 and set the SHARDING attribute to ADAPTIVE.

        CREATE TABLEGROUP tblgroup3 SHARDING = 'ADAPTIVE';
        
      2. Create a subpartitioned table named tbl5 by using a template and add the created table to the tblgroup3 table group.

        CREATE TABLE tbl5(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup3
        PARTITION BY LIST(col1)
        SUBPARTITION BY LIST(col2)
        SUBPARTITION TEMPLATE
        (SUBPARTITION mp0 VALUES('01'),
        SUBPARTITION mp1 VALUES('02'),
        SUBPARTITION mp2 VALUES('03')
        )
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
      3. Create a table named tbl6 that has the same partitioning type, partition count, and partition value as the table tbl5, and add the created table to the tblgroup3 table group.

        CREATE TABLE tbl6(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup3
        PARTITION BY LIST(col1)
        SUBPARTITION BY LIST(col2)
        SUBPARTITION TEMPLATE
        (SUBPARTITION mp0 VALUES('01'),
        SUBPARTITION mp1 VALUES('02'),
        SUBPARTITION mp2 VALUES('03')
        )
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
      4. View tables in the table group.

        SELECT * FROM SYS.DBA_OB_TABLEGROUP_TABLES WHERE tablegroup_name = 'TBLGROUP3';
        

        The result is as follows:

        +-----------------+-------+------------+----------+
        | TABLEGROUP_NAME | OWNER | TABLE_NAME | SHARDING |
        +-----------------+-------+------------+----------+
        | TBLGROUP3       | SYS   | TBL5       | ADAPTIVE |
        | TBLGROUP3       | SYS   | TBL6       | ADAPTIVE |
        +-----------------+-------+------------+----------+
        2 rows in set
        

    Add existing tables to a table group

    After you create a table group, you can use the ALTER TABLEGROUP statement to add existing tables that meet specific conditions to the table group. The syntax is as follows:

    ALTER TABLEGROUP tablegroup_name ADD [TABLE] table_name [, table_name...];
    

    where

    • tablegroup_name specifies the name of the table group to which the table is to be added.

    • table_name specifies the name of the table to be added to the table group. Separate multiple tables with commas (,).

      When multiple tables are added, the table names can be duplicate. If a table to be added already exists in the table group, the system does not return an error.

    The following examples show how to add existing tables to a table group:

    • Add an existing table to a table group with the SHARDING attribute set to NONE.

      1. Create a table group named tblgroup4 and set the SHARDING attribute to NONE.

        CREATE TABLEGROUP tblgroup4 SHARDING = 'NONE';
        
      2. Create a non-partitioned table named tbl7 and a template-based partitioned table named tbl8.

        CREATE TABLE tbl7 (col NUMBER);
        
        CREATE TABLE tbl8(col1 NUMBER,col2 VARCHAR2(50))
        PARTITION BY LIST(col1)
        SUBPARTITION BY LIST(col2)
        SUBPARTITION TEMPLATE
        (SUBPARTITION mp0 VALUES('01'),
        SUBPARTITION mp1 VALUES('02'),
        SUBPARTITION mp2 VALUES('03')
        )
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
      3. Add the tables tbl7 and tbl8 to the table group tblgroup4.

        ALTER TABLEGROUP tblgroup4 ADD tbl7,tbl8;
        
      4. View tables in the table group.

        SELECT * FROM SYS.DBA_OB_TABLEGROUP_TABLES WHERE tablegroup_name = 'TBLGROUP4';
        

        The result is as follows:

        +-----------------+-------+------------+----------+
        | TABLEGROUP_NAME | OWNER | TABLE_NAME | SHARDING |
        +-----------------+-------+------------+----------+
        | TBLGROUP4       | SYS   | TBL7       | NONE     |
        | TBLGROUP4       | SYS   | TBL8       | NONE     |
        +-----------------+-------+------------+----------+
        2 rows in set
        
    • Add existing tables to a table group with the SHARDING attribute set to PARTITION.

      1. Create a table group named tblgroup5 and set the SHARDING attribute to PARTITION.

        CREATE TABLEGROUP tblgroup5 SHARDING = 'PARTITION';
        
      2. Create two partitioned tables named tbl9 and tbl10 that have the same partition definition.

        CREATE TABLE tbl9(col1 NUMBER,col2 VARCHAR2(50))
        PARTITION BY LIST(col1)
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
        CREATE TABLE tbl10(col1 NUMBER,col2 VARCHAR2(50))
        PARTITION BY LIST(col1)
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
      3. Add the tables tbl9 and tbl10 to the table group tblgroup5.

        ALTER TABLEGROUP tblgroup5 ADD tbl9,tbl10;
        
      4. View tables in the table group.

        SELECT * FROM SYS.DBA_OB_TABLEGROUP_TABLES WHERE tablegroup_name = 'TBLGROUP5';
        

        The result is as follows:

        +-----------------+-------+------------+-----------+
        | TABLEGROUP_NAME | OWNER | TABLE_NAME | SHARDING  |
        +-----------------+-------+------------+-----------+
        | TBLGROUP5       | SYS   | TBL9       | PARTITION |
        | TBLGROUP5       | SYS   | TBL10      | PARTITION |
        +-----------------+-------+------------+-----------+
        2 rows in set
        
    • Add existing tables to a table group with the SHARDING attribute set to ADAPTIVE.

      1. Create a table group named tblgroup6 and set the SHARDING attribute to ADAPTIVE.

        CREATE TABLEGROUP tblgroup6 SHARDING = 'ADAPTIVE';
        
      2. Create two template-based subpartitioned tables named tbl11 and tbl12 that have the same partition definition.

        CREATE TABLE tbl11(col1 NUMBER,col2 VARCHAR2(50))
        PARTITION BY LIST(col1)
        SUBPARTITION BY LIST(col2)
        SUBPARTITION TEMPLATE
        (SUBPARTITION mp0 VALUES('01'),
        SUBPARTITION mp1 VALUES('02'),
        SUBPARTITION mp2 VALUES('03')
        )
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
        CREATE TABLE tbl12(col1 NUMBER,col2 VARCHAR2(50))
        PARTITION BY LIST(col1)
        SUBPARTITION BY LIST(col2)
        SUBPARTITION TEMPLATE
        (SUBPARTITION mp0 VALUES('01'),
        SUBPARTITION mp1 VALUES('02'),
        SUBPARTITION mp2 VALUES('03')
        )
        (PARTITION p0 VALUES('01'),
        PARTITION p1 VALUES('02')
        );
        
      3. Add the tables tbl11 and tbl12 to the table group tblgroup6.

        ALTER TABLEGROUP tblgroup6 ADD tbl11,tbl12;
        
      4. View tables in the table group.

        SELECT * FROM SYS.DBA_OB_TABLEGROUP_TABLES WHERE tablegroup_name = 'TBLGROUP6';
        

        The result is as follows:

        +-----------------+-------+------------+----------+
        | TABLEGROUP_NAME | OWNER | TABLE_NAME | SHARDING |
        +-----------------+-------+------------+----------+
        | TBLGROUP6       | SYS   | TBL11      | ADAPTIVE |
        | TBLGROUP6       | SYS   | TBL12      | ADAPTIVE |
        +-----------------+-------+------------+----------+
        2 rows in set
        

    References

    • Table groups

    • Create a table group

    • Query information about a table group

    • Modify the SHARDING attribute of a table group

    • Manage tables in a table group

    • Drop a table group

    Previous topic

    Query information about a table group
    Last

    Next topic

    Modify the SHARDING attribute of a table group
    Next
    What is on this page
    Limitations
    Prerequisites
    Specify a table group while creating a table
    Add existing tables to a table group
    References