CREATE SHARDING TABLE REFERENCE RULE
描述
CREATE SHARDING TABLE REFERENCE RULE
语法用于为分片表创建关联规则
语法定义
语法 铁路图
CreateShardingTableReferenceRule ::=
'CREATE' 'SHARDING' 'TABLE' 'REFERENCE' 'RULE' ifNotExists? referenceRelationshipDefinition (',' referenceRelationshipDefinition)*
ifNotExists ::=
'IF' 'NOT' 'EXISTS'
referenceRelationshipDefinition ::=
ruleName '(' tableName (',' tableName)* ')'
tableName ::=
identifier
补充说明
- 只能为分片表创建关联关系;
- 一张分片表只能具有一个关联关系;
- 关联的分片表应分布在相同的存储单元,并且分片个数相同。例如
ds_${0..1}.t_order_${0..1}
与ds_${0..1}.t_order_item_${0..1}
; - 关联的分片表应使用一致的分片算法。例如
t_order_${order_id % 2}
与t_order_item_${order_item_id % 2}
; ifNotExists
子句用于避免Duplicate sharding table reference rule
错误。
示例
1.创建关联关系
-- 创建关联关系之前需要先创建分片规则 t_order,t_order_item
CREATE SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item);
2.创建多个关联关系
-- 创建关联关系之前需要先创建分片规则 t_order,t_order_item,t_product,t_product_item
CREATE SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item), ref_1 (t_product,t_product_item);
3.使用 ifNotExists
子句创建关联关系
CREATE SHARDING TABLE REFERENCE RULE IF NOT EXISTS ref_0 (t_order,t_order_item);
保留字
CREATE
、SHARDING
、TABLE
、REFERENCE
、RULE
相关链接
当前内容版权归 ShardingSphere 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ShardingSphere .