Copy the table in MySQL and copy the Old_table table to the New_table table.
1. Do not copy table data, only copy structure.
The code is as follows |
Copy Code |
CREATE TABLE new_table like Old_table2 |
. By a SELECT query to copy, New_table table will lose primary key, index and other information.
Reference
The code is as follows |
Copy Code |
CREATE TABLE new_table as ( SELECT * From old_table ) |
3. Full Copy Table
The code is as follows |
Copy Code |
CREATE TABLE new_table like old_table; INSERT into new_table SELECT * from old_table; |
4. Copy only fields
The code is as follows |
Copy Code |
CREATE TABLE new_table as ( SELECT field1, field2 from old_table ) |
5. Partial copies
The code is as follows |
Copy Code |
CREATE TABLE new_table as ( SELECT * from old_table WHERE field1 = ' Mangguo ' ) |
Data replication
Copy data from old table to new table (assuming two table structures are different)
INSERT into new Table (Field 1, Field 2,.......) SELECT field 1, Field 2,...... From old table
Copy data from old table to new table (assuming two table structure)
INSERT into new Table select * from old table
CREATE Table New Table
SELECT * from old table where 1=2 is: let where condition not set