Mysql Copy table structure

Source: Internet
Author: User

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

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.