How to duplicate a table with keys & other structure features retained in MySQL?

后端 未结 3 473
无人共我
无人共我 2021-02-03 10:42

How to duplicate a table with keys & other structure features retained? including primary key, foreign keys, and indexes.

Can this be done with a single MySQL query?

3条回答
  •  萌比男神i
    2021-02-03 11:25

    duplicating a table from another table (with indexing and structure)cannot be done with a single query you will need need 2 queries.

    1) To create Duplicate table.

    CREATE TABLE Table2 LIKE Table1;

    This will create an exact copy of the table.

    2) Fill in the Duplicate table with values from original table.

    INSERT INTO Table2 SELECT * from Table1;

    will fill Table2 with all the records fom Table1

提交回复
热议问题