Table replication in MySQL: createtablelike and createtableasselect-mysql tutorial

Source: Internet
Author: User
Tags mysql tutorial
CREATETABLEALIKEB this method copies the complete field structure and Index of Table B to table A when copying Table B to table. CREATETABLEAASSELECTx, x, x, xxFROMBLIMIT0 this method only copies the field structure of Table B to table A, but does not copy the index of Table B to table. This method is more flexible.

Create table a like B. When table B is copied to table a, the complete field structure and Index of table B are copied to TABLE. Create table a as select x, xx from B limit 0 this method will only copy the field structure of table B to TABLE, however, indexes in Table B are not copied to table. This method is more flexible.


CREATE TABLE A LIKE B

In this way, when Table B is copied to table A, the complete field structure and indexes of Table B are copied to table.


Create table a as select x, xx from B LIMIT 0

This method only copies the field structure of Table B to table A, but does not copy the index of Table B to table. This method is flexible. you can specify the fields to be copied while copying the structure of the original table. you can also add the field structure as needed to copy the table.

Both methods do not copy the permission settings when copying a table. For example, if you have set permissions for Table B, after copying, table A does not have permissions similar to table B.

Leave it blank. next we will discuss the performance of the two types of replication tables.

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.