Simple example of mysql's MERGE storage engine _ MySQL

Source: Internet
Author: User
A simple example of mysql's MERGE storage engine: bitsCN.com

A simple example of mysql's MERGE storage engine

Role: you can merge multiple tables with the same structure into one table.

Supported versions: mysql5.1

Example:

Assume that there are several tables with the same structure: 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;

Create a summary table: the structure of article_total is as follows:

-- 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`);

The content of the article_total table contains the content of article_0 ', 'article _ 1', 'article _ 2', and 'article _ 3'.

The result of the select * from article_total table is the content of the data merging statements.

Command to modify which sub-tables to merge:

ALTER TABLE article_total  union =(article_0,article_1,article_2,article_3)


BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.