If you do not specify a table group when you create a table, you can add the created table to a table group later. You can add a table to a table group by changing the table group attribute of the table or using the ALTER TABLEGROUP ADD syntax.
Syntax
ALTER TABLE tblname TABLEGROUP = tablegroupname
ALTER TABLEGROUP tablegroupname ADD [TABLE] tblname [, tblname...]
Parameters
| Parameter | Description |
|---|---|
| tablegroupname | The name of the table group. |
| tblname | The name of the table. If multiple tables are added, separate the tables with a comma (,). When multiple tables are added, the table names can be duplicate. If a table already belongs to the target table group specified by tablegroupname, the system does not report an error. |
Examples
Example 1
Change the table group of a table:
Note
Do not use single quotation marks (') when changing the table group attribute. Otherwise, the names are case-sensitive.
Change the table group of the
ordrtable.obclient> ALTER TABLE ordr TABLEGROUP=tpcc_group; Query OK, 0 rows affectedView the table group attribute.
obclient> SHOW TABLEGROUPS; +-----------------+------------------------------+---------------+ | TABLEGROUP_NAME | TABLE_NAME | DATABASE_NAME | +-----------------+------------------------------+---------------+ | TPCC_GROUP | ORDL | SYS | | TPCC_GROUP | ORDR | SYS | | TPCC_GROUP | __idx_1101710651081553_IORDR | SYS | | oceanbase | NULL | NULL | +-----------------+------------------------------+---------------+ 4 rows in set
Example 2
Add a table to a table group.
Note
Before you add a table to a table group, make sure that the table has the same partitioning strategy as that of the table group.
View the current table group.
obclient> SHOW TABLEGROUPS WHERE TABLEGROUP_NAME = 'TGN'; Empty setAdd a table to the
TGNtable group.obclient> ALTER TABLEGROUP TGN ADD dws_ny; Query OK, 0 rows affectedView the information about the current table group.
obclient> SHOW TABLEGROUPS WHERE TABLEGROUP_NAME = 'TGN'; +-----------------+------------+---------------+ | TABLEGROUP_NAME | TABLE_NAME | DATABASE_NAME | +-----------------+------------+---------------+ | TGN | DWS_NY | SYS | +-----------------+------------+---------------+ 1 row in set