使用mysql的merge_mysql用merge合并表

merge合并表的要求

1.合并的表使用的必须是MyISAM引擎

2.表的结构必须一致,包括索引、字段类型、引擎和字符集

实例:

create table if not exists user1(

id int(11) not null auto_increment,

name varchar(50) default null,

sex int(1) not null default 0,

primary key (id)

)engine = MyISAM default charset = utf8 auto_increment=1;

create table if not exists user2(

id int(11) not null auto_increment,

name varchar(50) default null,

sex int(1) not null default 0,

primary key (id)

)engine = MyISAM default charset = utf8 auto_increment=1;

create table if not exists alluser(

id int(11) not null auto_increment,

name varchar(50) default null,

sex int(1) not null default 0,

primary key (id)

)engine = merge union=(user1,user2) insert_method = last auto_increment=1;

执行insert into alluser (name,sex) values (‘tian‘,1);报错如下:

ERROR 1168 (HY000): Unable to open underlying table which is differently defined or of non-MyISAM type or doesn‘t exist

百度了一下原来是默认字符集没写,修改如下

create table if not exists alluser1(

id int(11) not null auto_increment,

name varchar(50) default null,

sex int(1) not null default 0,

primary key (id)

)engine = merge union=(user3,user4) insert_method = last auto_increment=1 default charset=utf8;

执行insert into alluser1 (name,sex) values (‘tian‘,1);成功

执行select * from alluser1;显示如下:

+----+------+-----+

| id | name | sex |

+----+------+-----+

| 1 | tian | 1 |

+----+------+-----+

执行select * from user2;显示如下:

+----+------+-----+

| id | name | sex |

+----+------+-----+

| 1 | tian | 1 |

+----+------+-----+

mysql用merge合并表

标签:报错   引擎   err   sql   isa   diff   efault   nio   sel

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:http://www.cnblogs.com/shiwaitaoyuan/p/6483239.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值