A simple example of mysql's MERGE storage engine

Source: Internet
Author: User
For a simple example of mysql's MERGE storage engine, a simple example of mysql's MERGE storage engine can be used to MERGE multiple tables with the same structure into one table. The following example is supported: mysql5.1: suppose there are several tables with the same structure: article_0, article_1, article_2, article_3, -- Tablearticle_0D

For a simple example of mysql's MERGE storage engine, a simple example of mysql's MERGE storage engine can be used to MERGE multiple tables with the same structure into one table. The following example is supported: mysql5.1: suppose there are several tables with the same structure: article_0, article_1, article_2, article_3, -- Table article_0 D

A simple example of mysql's MERGE storage engine

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

Create table 'Article _ 0 '(
'Id' bigint (20) not null,
'Subobject' 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,
'Subobject' 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,
'Subobject' 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,
'Subobject' 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" DDL

Create table 'Article _ total '(
'Id' bigint (20) not null,
'Subobject' 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)

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.