Mysql-merge table

Source: Internet
Author: User
Merge table Note: 1. The structure of each sub-table must be consistent. The structure of the master table and sub-table must be consistent. 2. The index of each sub-table will exist in the merge table, therefore, you cannot perform a unique search based on the index in the merge table. 3. The sub-table must be MyISAM engine 4AUTO_INCREMENT and will not work as expected. Create table statement createtabletab

Merge table Note: 1. The structure of each sub-table must be consistent. The structure of the master table and sub-table must be consistent. 2. The index of each sub-table will exist in the merge table, therefore, you cannot perform a unique search based on the index in the merge table. 3 sub-tables must be MyISAM engine 4 AUTO_INCREMENT and will not work as expected. Create table tab

Merge table


Note: 1. The structure of each sub-table must be consistent. The structure of the master table and sub-table must be consistent. 2. The index of each sub-table exists in the merge table, therefore, you cannot perform a unique search based on the index in the merge table. 3 sub-tables must be MyISAM engine 4 AUTO_INCREMENT and will not work as expected. Create table tablename (normal field) engine = merge insert_method = lastinsert_method: There are two values: LAST. If you execute the insert command to operate the merge table, the insert operation adds data to the last sub-table. Similarly, when inserting data, the data is added to the FIRST sub-table. Example: create table user1 (id int (10) not null auto_increment, name varchar (50), sex int (1), primary key (id) engine = myisam charset = utf8; create table user2 (id int (10) not null auto_increment, name varchar (50), sex int (10), primary key (id) engine = myisam charset = utf8; insert into user1 (name, sex) values ('zhang san', 0); insert into user2 (name, sex) values ('lisi', 1 ); mysql> select * from user1; + ---- + ------ + | id | name | sex | + ---- + ------ + | 1 | Zhang San | 0 | + ---- + ------ + mysql> select * from user2; + ---- + ------ + | id | name | sex | + ---- + ------ + | 1 | lisi | 1 | + ---- + ------ + create table alluser (id int (10) not null auto_increment, name varchar (50), sex int (10), index (id) type = merge union = (user1, user2) insert_method = last; mysql> select * from alluser; + ---- + ------ + | id | name | sex | + ---- + ------ + | 1 | Zhang San | 0 | 1 | lisi | 1 | + ---- + ------ + ------ + mysql> insert into alluser (name, sex) values (' ', 0); mysql> select * from user1; + ---- + ------ + | id | name | sex | + ---- + ------ + | 1 | Zhang San | 0 | + ---- + ------ + 1 row in set (0.00 sec) mysql> select * from user2; + ---- + ------ + | id | name | sex | + ---- + ------ + | 1 | lisi | 1 | 2 | | 0 | + ---- + ------ + ------ + 2 rows in set (0.00 sec) // This data is stored in user2 because our insert_method parameter is set to lastmysql> update alluser set sex = replace (sex,) where id = 2; + ---- + ------ + | id | name | sex | + ---- + ------ + | 1 | Zhang San | 0 | 1 | lisi | 1 | 2 | | 1 | + ---- + ------ +


Author: maildocgaojingru published on 17:32:27 Original article link

Read: 53 comments: 0 view comments

Original article address: mysql-merge table. Thank you for sharing it with the original author.

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.