时间:2021-07-01 10:21:17 帮助过:37人阅读
关于mysql的MERGE存储引擎简单例子
作用:可以将多个表结构相同的表 和合并到一个表中
版本支持:mysql5.1
如下例子:
假设有如下几个表:结构完全相同 article_0,article_1,article_2,article_3,
-- Table "article_0" DDLCREATE TABLE `article_0` ( `id` bigint(20) NOT NULL, `subject` varchar(200) NOT NULL, `content` text NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;-- Table "article_1" DDLCREATE TABLE `article_1` ( `id` bigint(20) NOT NULL, `subject` varchar(200) NOT NULL, `content` text NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;-- Table "article_2" DDLCREATE TABLE `article_2` ( `id` bigint(20) NOT NULL, `subject` varchar(200) NOT NULL, `content` text NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;-- Table "article_3" DDLCREATE TABLE `article_3` ( `id` bigint(20) NOT NULL, `subject` varchar(200) NOT NULL, `content` text NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;
建立总表:article_total 结构如下:
-- Table "article_total" DDLCREATE TABLE `article_total` ( `id` bigint(20) NOT NULL, `subject` varchar(200) NOT NULL, `content` text NOT NULL, PRIMARY KEY (`id`)) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 UNION=(`article_0`,`article_1`,`article_2`,`article_3`);
那么 article_total 表的内容就包含了article_0`,`article_1`,`article_2`,`article_3`的内容
select * from article_total 表的结果就是各个表述数据合并的内容
修改合并哪些子表的命令:
ALTER TABLE article_total union =(article_0,article_1,article_2,article_3)