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;
最新文章
- JSON 的标准:双引号而非单引号!
- Sql--order by、desc降序、top
- 软件工程(FZU2015)赛季得分榜,第10回合(alpha冲刺)
- android wifi P2P CONNECT, INVITE和JOIN流程选择
- DOM--4 响应用户操作和事件(1)
- 调试WEB APP多设备浏览器
- Never-build package 'XXXX' requires always-build package 'EhLib70'
- hibernate--student_course_score
- ES2:ElasticSearch 集群配置
- CSS3特效----制作3D旋转导航
- My操作小技巧
- [新三板摘牌]国资企业济南华光光电去年终止拟IPO今年摘牌新三板
- js 图片转换base64 base64转换为file对象
- c# 抽象类与接口【学习笔记】
- Scrapy中将item字段转为简体or繁体
- Linux 读取 (*.xls)文件读取,使用libxls库
- 【实践报告】Linux基础实践一
- 从Encoder到Decoder实现Seq2Seq模型
- 部分Linux时区改为东八区的方法
- Matlab-9:中心差分方法解常微分算例(SOR完整版)