MySQL copies the table structure and content to the SQL statement in another table.
1. copy the table structure and data to the new table
The code is as follows:
Create table new TABLE
SELECT * FROM old table
2. only copy the table structure to the new table
The code is as follows:
Create table new TABLE
SELECT * FROM old table WHERE 1 = 2
That is, make the WHERE condition invalid.
Method 2: (mysql of earlier versions is not supported, mysql 4.0.25 is not supported, and mysql 5 is supported)
The code is as follows:
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)
The code is as follows:
Insert into new table
SELECT * FROM old table
4. copy the data from the old table to the new table (assuming the two tables have different structures)
The code is as follows:
Insert into new table (Field 1, field 2 ,.......)
SELECT Field 1, field 2 ,...... FROM old table