本文介绍如何在 OceanBase 数据库的 Oracle 模式下,创建数据表时指定表组。
语法
表组可以在创建表的时候指定,SQL 查询语法格式如下:
CREATE TABLE table_name (column_name data_type [, column_name data_type] ) TABLEGROUP = tablegroup_name;
参数解释
| 参数 | 描述 |
|---|---|
| table_name | 指定表名。 |
| column_name | 指定字段名。 |
| data_type | 指定数据类型。 |
| tablegroup_name | 表组名称,最长 64 个字符,字符只能有大小写英文字母,数字和下划线,而且必须以字母或下划线开头,并且不能使用 OceanBase 的关键字。 |
示例
如下创建订单表和订单明细表,业务上这两个表经常要关联查询,所以建议放到同一个表组中。
创建订单表
ordr。create table ordr ( o_w_id int, o_d_id int, o_id int, o_c_id int, o_carrier_id int, o_ol_cnt int, o_all_local int, o_entry_d date, index iordr(o_w_id, o_d_id, o_c_id, o_id) local, primary key (o_w_id, o_d_id, o_id) ) tablegroup tpcc_group partition by hash(o_w_id) partitions 6;创建订单明细表
ordl。create table ordl ( ol_w_id int, ol_d_id int, ol_o_id int, ol_number int, ol_delivery_d date, ol_amount decimal(6, 2) , ol_i_id int , ol_supply_w_id int , ol_quantity int, ol_dist_info char(24), primary key (ol_w_id, ol_d_id, ol_o_id, ol_number) )tablegroup tpcc_group partition by hash(ol_w_id) partitions 6;查看已放入
tpcc_group表组的订单表和订单明细表。obclient> SHOW TABLEGROUPS; +-----------------+------------+---------------+ | TABLEGROUP_NAME | TABLE_NAME | DATABASE_NAME | +-----------------+------------+---------------+ | TPCC_GROUP | ORDL | SYS | | TPCC_GROUP | ORDR | SYS | +-----------------+------------+---------------+ 2 rows in set