Create or copy an existing MySQL table to a new table

April 6, 2008 – 4:28 pm

You can create a new table that looks like another table. That is newly created table will have same structure and definition as of an existing table. The definitions that are copied are: Column names, Data type, precision, length, and scale, Column text.

CREATE TABLE Employee1 LIKE Employee;

Above statement creates the new table Employee1 same as Employee table with the same columns and definition in it.

INSERT Employee1 SELECT * FROM Employee;

This statement copies the data from Employee to new table Employee1. You can also specify the specific database names if you want to copy the database1.table1 in database2 as table1.

Share/Save/Bookmark

Post a Comment