Home > Database > Mysql Tutorial > 关于mysql的MERGE存储引擎简单例子_MySQL

关于mysql的MERGE存储引擎简单例子_MySQL

WBOY
Release: 2016-06-01 13:29:06
Original
987 people have browsed it

bitsCN.com

关于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;
Copy after login

建立总表: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`);
Copy after login

那么 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)
Copy after login

 


bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template