sql分表
一、创建表
create table student(
id bigint auto_increment primary key,
name varchar(20) not null);
二、添加数据
1、insert into student(id,name) values (1,'jack');
2、执行多次
insert into student(name) select name from student;
三、创建两个分表student1和student2
create table tb_student1(
id bigint primary key auto_increment ,
name varchar(20) not null
);
四、创建主表
create table tb_student(
id bigint primary key auto_increment ,
name varchar(20) not null
)ENGINE=MERGE UNION=(tb_student1,tb_student2) INSERT_METHOD=LAST;
五、数据分到两个分表中
insert into tb_student1(id,name) select id,name from student where id%2=0;
insert into tb_student2(id,name) select id,name from student where id%2=1;
总表只是一个外壳,存取数据发生在一个一个的分表里面。