zoukankan      html  css  js  c++  java
  • mysql分表操作

    ---创建源数据表,用来往分表插入测试数据
    create table member(
    id bigint auto_increment primary key,name varchar(20),
    sex tinyint not null default '0'
    )engine=myisam default charset=utf8 auto_increment=1;

    ---编造数据
    insert into member(id,name,sex) values (1,'jacson','0');

    insert into member(name,sex) select name,sex from member;

    insert into member(name,sex) select name,sex from member;

    insert into member(name,sex) select name,sex from member;


    -----/*分表*/----------
    ----创建两个分表tb_member1,tb_member2

    DROP table IF EXISTS tb_member1;

    create table tb_member1(
    id bigint primary key auto_increment ,
    name varchar(20),
    sex tinyint not null default '0'
    )ENGINE=MyISAM/*不支持事物处理*/ DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

    DROP table IF EXISTS tb_member2;

    create table tb_member2(
    id bigint primary key auto_increment ,
    name varchar(20),
    sex tinyint not null default '0'
    )ENGINE=MyISAM/*不支持事物处理*/ DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;


    ---创建主表tb_member
    DROP table IF EXISTS tb_member;
    create table tb_member(
    id bigint primary key auto_increment ,
    name varchar(20),
    sex tinyint not null default '0'
    )ENGINE=MERGE UNION=(tb_member1,tb_member2) INSERT_METHOD=LAST CHARSET=utf8 AUTO_INCREMENT=1 ;


    ----查看一下tb_member表的结构:desc tb_member;


    ----把数据分到两个分表中去:

    insert into tb_member1(id,name,sex) select id,name,sex from member where id%2=0;

    insert into tb_member2(id,name,sex) select id,name,sex from member where id%2=1;


    -----查看一下主表的数据:select * from tb_member;

  • 相关阅读:
    ASIX配置vlan tag能被wireshark获取
    翻译-cmake教程
    Manjaro打造开发环境
    Frida入门
    安卓应用启动底层执行逻辑
    集合框架
    oracle清除日志内存
    flutter widgets目录
    给设备添加udid
    5.class
  • 原文地址:https://www.cnblogs.com/zyzloner/p/6651394.html
Copyright © 2011-2022 走看看