MySQL copies the SQL statements in the table structure and content to another table

  • 2020-06-19 11:54:35
  • OfStack

1. Copy the table structure and data to the new table


CREATE TABLE The new table
SELECT * FROM The old table

2. Only copy the table structure to the new table


CREATE TABLE The new table
SELECT * FROM The old table WHERE 1=2

That is: make WHERE condition not true.

Method 2:(the lower version of mysql is not supported, mysql4.0.25 is not supported, mysql5 is already supported)


CREATE TABLE The new table
LIKE The old table

3. Copy the data of the old table to the new table (assuming 1 sample structure of the two tables)


INSERT INTO The new table
SELECT * FROM The old table

4. Copy the data of the old table to the new table (assuming that the two tables have different structure)


INSERT INTO The new table ( field 1, field 2, ... .)
SELECT field 1, field 2, ... FROM The old table


Related articles: