MySQL之Merge引擎

MySQL之Merge引擎

MySQL可以通过Merge引擎将相同的MyISAM表逻辑组织起来

  • MyISAM引擎表
    创建表 in_num_m1 和 in_num_m2,并向其中插入示例数据
CREATE TABLE `in_num_m1`
(
    `num_id`  int(11) NOT NULL DEFAULT '0',
    `num_val` int(11)          DEFAULT NULL
) ENGINE = MyISAM;

CREATE TABLE `in_num_m2`
(
    `num_id`  int(11) NOT NULL DEFAULT '0',
    `num_val` int(11)          DEFAULT NULL
) ENGINE = MyISAM; 

数据如下图
在这里插入图片描述

  • Merge引擎表
    关联之前的两张MyISAM引擎的表 in_num_m1 和 in_num_m2
CREATE TABLE `in_num_mg`
(
    `num_id`  int(11) NOT NULL DEFAULT '0',
    `num_val` int(11)          DEFAULT NULL
) ENGINE = merge
  union (in_num_m1,in_num_m2);

查询 in_num_mg 表可以发现数据为表 in_num_m1 和 in_num_m2 的union
在这里插入图片描述
此时我们向 in_num_m1 表中插入数据

insert into in_num_m1(num_val) values(5201)
select * from in_num_m1;

在这里插入图片描述
查询in_num_mg
在这里插入图片描述
注意:表in_num_mg为只读

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值