[solution] Copy entire table ( or partial table ) to a new table


min read

My profile

Share this:

To make a copy of the table recipes which is in a different database called production into a new table called recipes_new in the currently selected database, use these two commands:

[code:1:7ab2abe5fb]CREATE TABLE recipes_new LIKE production.recipes;
INSERT recipes_new SELECT * FROM production.recipes;[/code:1:7ab2abe5fb]

This stuff actually works !

Now for a [b:7ab2abe5fb]partial table[/b:7ab2abe5fb]: ( oldtable contains 10 colums/fields, newtable only 4 including primary key, which we solve by NULL-ing the primary incremental key )
[code:1:7ab2abe5fb]INSERT `newtable` select NULL, `ip`,`ip_forwarded`,`time` FROM `oldtable`[/code:1:7ab2abe5fb]


Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *