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
错误。-- 创建关联关系之前需要先创建分片规则 t_order,t_order_item
CREATE SHARDING TABLE REFERENCE RULE ref_0 (t_order,t_order_item);
-- 创建关联关系之前需要先创建分片规则 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);
ifNotExists
子句创建关联关系CREATE SHARDING TABLE REFERENCE RULE IF NOT EXISTS ref_0 (t_order,t_order_item);
CREATE
、SHARDING
、TABLE
、REFERENCE
、RULE