zoukankan      html  css  js  c++  java
  • mysql将一个表拆分成多个表(一)(转载)

    转载

    直接根据数据量进行拆分

    有一个5000条数据的表,要把它变成没1000条数据一个表的5等份。

    假设:表名:xuesi 主键:kid
    xuesi共有5000条数据,kid从1到5000自动增长
    题目:将xuesi分成5个表 每个表1000条不同的数据

    方法1:
    create table xuesi1 select * from xuesi order by kid limit 0,1000;
    create table xuesi2 select * from xuesi order by kid limit 1000,1000;
    create table xuesi3 select * from xuesi order by kid limit 2000,1000;
    create table xuesi4 select * from xuesi order by kid limit 3000,1000;
    create table xuesi4 select * from xuesi order by kid limit 4000,1000;

    以上方法 是根据大表xuesi的主键kid 创建了xuesi1,xuesi2,xuesi3,xuesi4,xuesi5 五等份的小表
    不足:primary key 属性丢失

    方法2:
    create table xuesi1 like xuesi;
    insert into xuesi1 select * from xuesi order by limit 0,1000;
    create table xuesi2 like xuesi;
    insert into xuesi2 select * from xuesi order by limit 1000,1000;
    create table xuesi2 like xuesi;
    insert into xuesi3 select * from xuesi order by limit 2000,1000;
    create table xuesi3 like xuesi;
    insert into xuesi4 select * from xuesi order by limit 3000,1000;
    create table xuesi5 like xuesi;
    insert into xuesi5 select * from xuesi order by limit 4000,1000;

  • 相关阅读:
    C# 添加修改防火墙端口及程序
    Winform 多线程--解决界面卡死问题
    ScreenOper
    KVM的VPS主机在Centos6.x下修改系统时间
    Java IO和File类
    Java动态代理Proxy类源码分析
    Java IO之字节流
    Java IO之字符流
    两台计算机之间如何通讯
    Java引用类型原理
  • 原文地址:https://www.cnblogs.com/macT/p/12055308.html
Copyright © 2011-2022 走看看