Sometimes we need to copy the table structure of a table intact to generate a new table, MySQL provides two convenient ways
First, like method
The like method can replicate the results of a table in exactly the same way as a new table, including the notes, indexes, primary key foreign keys, storage engines, etc. of the copied table.
Grammar
CREATE [temporary] TABLE [IF not EXISTS] tbl_name like | ( like Old_tbl_name)}
For example:
CREATE TABLE IF not EXISTS ' news_dynamic ' ( like ' news_bulletin ');
Second, select method
Grammar
CREATE [temporary] TABLE [IF not EXISTS] Tbl_name SELECT ... (SomeSelectorUnion statement)
For example
CREATE TABLE IF not EXISTS SELECT * from
Three, the difference
Like method: The Like method is actually a method that specifically replicates the table structure, but it replicates only the structure and related properties of the table and does not replicate the data
Select method: Strictly speaking, the Select method does not understand the method of copying table structure, in fact, it just executes a SELECT query statement, so the result of the copy contains only the fields and data of select, the other table properties have the configuration file of the system, including the storage engine, The default character set, and so on, is determined by the system's default configuration.
Mysql Copy table structure