Sending tables between databases

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

Sending tables between databases

Post by bwv2 »

I have one database with a bunch of big tables in it. I would like to separate it into 4 different databases by moving tables from the big database to the others that I will create.

Any thoughts on the easiest way of doing this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

CREATE TABLE `newDatabase`.`newTable` LIKE `oldDatabase`.`oldTable`

Code: Select all

INSERT INTO `newDatabase`.`newTable` (`field1`, `field2`, .. `fieldn`) SELECT `field1`, `field2`, .. `fieldn` FROM `oldDatabase`.`oldTable`
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Alternate way

Post by dibyendrah »

Without field can also be done if all fields are to be copied.

Code: Select all

INSERT INTO `database`.`new_table` SELECT * FROM `database`.`old_table` ;
Cheers,
Dibyendra
Post Reply