Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 16:15:03
Original
1202 people have browsed it

关于mysql的MERGE存储引擎简单例子 关于mysql的MERGE存储引擎简单例子 作用:可以将多个表结构相同的表 和合并到一个表中 版本支持:mysql5.1 如下例子: 假设有如下几个表:结构完全相同 article_0,article_1,article_2,article_3, -- Table article_0 D

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

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


作用:可以将多个表结构相同的表 和合并到一个表中

版本支持:mysql5.1


如下例子:

假设有如下几个表:结构完全相同 article_0,article_1,article_2,article_3,

 

-- Table "article_0" DDL

CREATE 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" DDL

CREATE 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" DDL

CREATE 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" DDL

CREATE 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" DDL

CREATE 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)

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!