MySQL Merge table with merge

Source: Internet
Author: User

Requirements for Merge consolidation tables

1. The merged table must be MyISAM engine

2. The structure of the table must be consistent, including index, field type, engine, and character set

Instance:

CREATE table if not exists user1 (

ID Int (one) not NULL auto_increment,

Name varchar () default NULL,

sex int (1) NOT null default 0,

Primary KEY (ID)

) engine = MyISAM default charset = UTF8 auto_increment=1;

CREATE table if not exists user2 (

ID Int (one) not NULL auto_increment,

Name varchar () default NULL,

sex int (1) NOT null default 0,

Primary KEY (ID)

) engine = MyISAM default charset = UTF8 auto_increment=1;

CREATE table if not exists alluser (

ID Int (one) not NULL auto_increment,

Name varchar () default NULL,

sex int (1) NOT null default 0,

Primary KEY (ID)

Engine = Merge union= (user1,user2) Insert_method = Last auto_increment=1;

Execute INSERT INTO AllUser (name,sex) VALUES (' Tian ', 1), with the following error:

ERROR 1168 (HY000): Unable to open underlying table which is differently defined or of Non-myisam type or doesn ' t exist

Baidu a bit originally is the default character set is not written, modified as follows

CREATE table if not exists alluser1 (

ID Int (one) not NULL auto_increment,

Name varchar () default NULL,

sex int (1) NOT null default 0,

Primary KEY (ID)

Engine = Merge union= (user3,user4) Insert_method = last auto_increment=1 default Charset=utf8;

Execute INSERT INTO Alluser1 (name,sex) VALUES (' Tian ', 1);

Execute SELECT * from Alluser1, shown below:

+----+------+-----+
| ID | name | sex |
+----+------+-----+
| 1 | Tian | 1 |
+----+------+-----+

Execute SELECT * from User2, shown below:

+----+------+-----+
| ID | name | sex |
+----+------+-----+
| 1 | Tian | 1 |
+----+------+-----+

MySQL Merge table with merge

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.