F.Joe F.Joe - 5 months ago 7
SQL Question

How can I duplicate a MySQL table (including structure and indexes)?

How can I duplicate the data of MySQL table, copy old one to new one?

This is what I tried but this copies the data and the structure, but not the indexes:

create table {new_table}
select * from {old_table};


This does not copy the data but only the structure and indexes:

create table {new_table}
like {old_table};

Answer

Do that in two queries.

create table newtable
Like oldtable;
Insert newtable
Select * From oldtable;

Hopefully, this should work

run mysql create table by selecting another and copied the indexes automatically