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