To copy structure in MySQL with data you need to execute the following MySQL statements:
use dbname;
create table new_table_name
select * from existing_table_name;
If you require the copy of structure without data then you need to execute the following MySQL Statements:
use dbname;
create table new_table_name
select * from existing_table_name where 1=0;
But the above MySQL statements copy the structure without indexes and constraints. To copy the structure with indexes and constraints you need to execute the following MySQL Statements:
CREATE TABLE `new_table_name` LIKE `existing_table_name`;
The above statement only create the copy of the structure of table with indexes and constraints but not the data. To copy the data with structure(with indexes and constraints) you need to execute following MySQL statements:
CREATE TABLE `new_table_name` LIKE `existing_table_name`;
INSERT INTO `new_table_name` SELECT * FROM `existing_table_name`;
0 Comment(s)