Database: Table Structure and Data Replication instance, copying instance

Source: Internet
Author: User

Database: Table Structure and Data Replication instance, copying instance
Solution 1
1.1
Copy the entire table (including data without primary key index): old_table ---> new_table
Create table new_table SELECT * FROM old_table;
1.2
Copy the entire table structure (no data, no primary key index): old_table ---> new_table
Create table new_table SELECT * FROM old_table where 0;


Solution 2
2.1
Copy the entire table structure (no data, including primary key index): old_table ---> new_table
Create table new_table LIKE old_table
2.2
Copy the entire table (including data with no primary key index)
Create table new_table (SELECT * FROM old_table)


Solution 3
3.1
Copy the entire table (including data, primary keys, and indexes)
Create table new_table LIKE old_table;
Insert into new_table SELECT * FROM old_table;


If it is not a full table copy or cross-database operation, you can change the SELECT * FROM old_table; statement.
For example:
Insert into new_table SELECT username, password FROM old_table;
Create table new_db.new_table LIKE old_db.old_table;

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.