If you do not specify a table group when creating a table, you can add the table to a table group afterward. 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 | +-----------------+------------+---------------+ | oceanbase | NULL | NULL | | tgh | NULL | NULL | | tpcc_group | ordr | test | +-----------------+------------+---------------+ 3 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; +-----------------+------------+---------------+ | Tablegroup_name | Table_name | Database_name | +-----------------+------------+---------------+ | oceanbase | NULL | NULL | | tgh | NULL | NULL | | tpcc_group | NULL | NULL | +-----------------+------------+---------------+ 3 rows in setAdd a table to the
tpcc_grouptable group.obclient> ALTER TABLEGROUP tpcc_group ADD ordr; Query OK, 0 rows affectedView the information about the current table group.
obclient> SHOW TABLEGROUPS; +-----------------+------------+---------------+ | Tablegroup_name | Table_name | Database_name | +-----------------+------------+---------------+ | oceanbase | NULL | NULL | | tgh | NULL | NULL | | tpcc_group | ordr | test | +-----------------+------------+---------------+ 3 rows in set