phpmyadmin/ mysql how to copy a table with all its constraints I tried to copy a table which is connected to another table through a foreign key using 

$query = "CREATE TABLE table1 AS SELECT * FROM table 2";


but when I run this query it copies every thing but the constraints are not copied.

Is there any way I can run a script through phpmyadmin or write a function that preserve the constraints and the references ?
Within phpMyAdmin, if you go to the table you wish to copy and click the "Operations" tab, there should be a section "Copy table to (database.table)"

Here you will be able to copy the table with the same constraints as the table you are trying to copy.