MySQL copy table structure the difference between create table as and like

Source: Internet
Author: User

For MySQL to replicate the same table structure method, there are create table as and create table like two kinds, what is the difference?

CREATE TABLE t2 as SELECT * from T1 where 1=2;
or limit 0;

The T2 table (the new table) created by as is missing the index information for the T1 table (source table), with only the same table structure and no indexes.

CREATE table t2 like T1;

The new table created by like contains the full table structure and index information for the source table.

The use of the two:
As is used to create the same table structure and copy the source table data.
Like is used to create a full table structure and all indexes.

Oracle supports as, and only the table structure is not indexed, and Oracle does not support like.
There are two ways to copy a table without copying the permissions on the table settings. For example, the permissions set for Table B, after replication, table A does not have permissions similar to Table B.

MySQL copy table structure the difference between create table as and like

Related Article

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.