I’m trying to create an exact duplicate of another table via php by using SHOW CREATE TABLE.
I only want to change the table name, but I haven’t figured out how to do that yet. If the old table’s name is table_1, I want the new one to be table_2.
This didn’t work. Didn’t really expect it to, but that’s how far I got:
$t = $DB->fetch("SHOW CREATE TABLE table_1");
$t[0] = "table_2";
$DB->query($t[1]);
The following query will create new table, column attributes and indexes will also be copied.
And if you also want the rows copied, then execute following query after executing the above
http://www.mysqlfaqs.net/mysql-faqs/Data-Back-Up/How-to-create-duplicate-table-in-MySQL
http://www.tech-recipes.com/rx/1487/copy-an-existing-mysql-table-to-a-new-table/