Differences between create table as And like in MySQL

Source: Internet
Author: User


There are two ways for MySQL to copy the same table structure: Create Table as and create table like. What is the difference?

Create Table T2 as select * from T1 where 1 = 2; or limit 0;

The T2 table (new table) created by as lacks the index information of table T1 (source table). Only the table structure is the same and there is no index.

Create Table T2 like T1;

The new table created by like contains the complete table structure and index information of the source table.

Usage:

As is used to create the same table structure and copy the source table data

Like is used to create the complete table structure and all indexes.

Oracle supports as, and only the table structure has no indexes. Oracle does not support 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.