How to copy content of one table to another table ?

Started by Dipak Bhoi, June 19, 2015, 03:22:52 PM

Previous topic - Next topic

Dipak Bhoi

Hello folks,

I found a new and simple way to copy content of one table to another table within same database using command prompt. You can copy/duplicate one table to new table at the time to creating new table.

Go to mysql prompt and switch to the database in which you wish to copy/duplicate table.

Quotemysql> use database_name;

mysql> CREATE TABLE new_table_name SELECT * FROM old_table_name;
Above CREATE TABLE command will create a new_table_name' like table 'old_table_name' and entire data from old table will be copied to new table. You can break this operation into two steps as well. Let see below two command which will perform same operation.

Quotemysql>CREATE TABLE new_table_name LIKE old_table_name;

Quotemyslq>INSERT INTO new_table_name SELECT * FROM `old_table_name`;

Using above commands you can create new table like old table and then copy entire data of old table into new table.

Hope this post will help..

That's all....... Enjoy !!  :);) :)

MilesWeb - 30-Day Money Back
cPanel Web Hosting - cPanel Hosting in India
Grab a Free SSL for your website.  WordPress Optimized Solution.