Create new table exactly like another one with data

Uncategorized 0 Comment 52

Lets say you have a table in your mysql. Now you want to create a new table which will have exactly the same table structure of old one. Using the LIKE keyword of mysql you can easily create you desired table.

CREATE TABLE new_table LIKE old_table;

This will create a table “new_table” which will have exactly the same structure of “old_table”. Remember, the data will not copy to the “new_table”. You have to write other command to do that.
The command for creating the table with data will be,

CREATE TABLE new_table SELECT * FROM old_table;

Insert date from “old_table” to “new_table” if the both table structure is same then mysql query will be,

INSERT INTO new_table SELECT * FROM old_table;

Leave a comment

You must be logged in to post a comment.

© 2016 4frienz. Powered By Flowers

Back to Top