MySQL uses SQL statements to copy tables

Source: Internet
Author: User
1. Copy the table structure and data to the new table create table new table select * from old table this method will copy all the content in oldtable, of course we can use Delete from newtable; to delete. However, the worst thing about this method is that the new table does not have the primary key, extra (auto_increment) and other attributes of the old table. You need to use "alter" to add it yourself, and it is easy to make a mistake. 2. copy only the table structure to the new table create table new table select * from old table where 1 = 2 or create table new table like old table 3. copy the data from the old table to the new table (assuming the two tables have the same structure)) insert into new table select * from old table 4. Copy data from old table to new table (assuming the two tables have different structures) insert into new table (Field 1, field 2 ,.......) select Field 1, Field 2 ,...... from old table 5. You can copy Table 1 structure to table 2 select * into Table 2 from table 1 where 1 = 2 6. You can copy all Table 1 content to table 2 select * into table 2 from table 1 7, show create table old table; this will list the creation commands of the old table. We only need to copy the command and change the table name to create a table with the same name.
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.