Analysis of the differences between create table as and like in MySQL

  • 2020-12-13 19:09:14
  • OfStack

This paper analyzes the differences between create table as and like in MySQL. To share for your reference, the details are as follows:

For replicating the same table structure of mysql, there are 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 created by as (the new table) lacks the index information of the t1 table (the source table), except that the table structure is the same without indexes.
create table t2 like t1 ;

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

2 uses:

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

like is used to create the full table structure and all indexes

oracle supports as and also has only table structures without indexes
oracle does not support like.

I hope this article has been helpful in designing your MySQL database.


Related articles: