表相關的DDL語句
更新時間 2025-06-17 10:20:04
最近更新時間: 2025-06-17 10:20:04
分享文章
本文為您介紹dbproxy表相關的DDL語句。
表相關ddl:create/alter/drop table
基礎DDL語句包括:create table、alter table、drop table
create table只會在標準庫中執行
alter table、drop table要根據分片規則的設置在標準庫和對應的分片庫上執行
UDAL對數據庫建表DDL語句進行了擴展,支持設置分片規則。執行設置分片規則語句,dbproxy根據分片規則從標準庫獲取建表語句,再到對應的分片上執行。示例:
sharding @@table name='bill' set type='global' --設置全局表
sharding @@table name='bill' set type='single' and dn='dn1' --設置單片表
sharding @@table name='bill' set type='sharding' and sharding_func='mod-long-6' and sharding_id='sharding_id' and - sharding_area='sharding_area' and dn='dn1,dn2,dn3' --設置分片表(dn參數可選)
sharding @@table name='bill' set type='inner' and inner_total='10' and inner_sharding_id='inner_sharding_id' and inner_sharding_func = 'inner_sharding_func' and dn='dn1' --設置單片表的庫內分表
sharding @@table name='bill' set type='inner' and sharding_func='modlong-6' and sharding_id='sharding_id' and sharding_area='sharding_area' and inner_sharding_id='inner_sharding_id' and inner_sharding_func = 'inner_sharding_func' and dn='dn1,dn2,dn3' --設置分片表的庫內分表(dn參數可選)支持create table和sharding合并為一條sql執行,即通過/* {sharding語句} */將sharding語句做為hint注釋,拼接到create table語句后面。使用示例如下:
CREATE TABLE IF NOT EXISTS `etasd9` ( `employee_id` int NOT NULL, PRIMARY KEY (`employee_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8/*sharding @@table name='etasd9' set type='sharding' and sharding_algo='PartitionByMod' and sharding_id='employee_id' and dn='asdadada_1,asdadada_2,asdadada_3,asdadada_4,asdadada_5'; */;