What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Copying database

Copying database
Author: Message:
Weyzza
Veteran Member
*****

Avatar
SoCal sunset > *

Posts: 1170
Reputation: 29
– / Male / –
Joined: May 2003
O.P. Copying database
Hi,

I need this help quick.
I'm still looking for the answer, but I need help from some people who are knowledgeable in SQL.

How to copy tables from a database to another database using a single query?
I'm using mySQL if that matters.

Thanks.
Registered 7647 days, 14 hours, 26 minutes, 10 seconds ago.
Happy Birthday, WDZ

05-02-2006 05:58 PM
Profile PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: Copying database
http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

INSERT INTO targetDB.targetTable SELECT * FROM sourceTable

Of course, you will need to create the target table and set up its structure first. I don't know of a way to copy the structure and data with one query. :-/

Edit: For quickly copying the structure, maybe you could use...

CREATE TABLE targetDB.targetTable LIKE sourceTable

http://dev.mysql.com/doc/refman/5.0/en/create-table.html

Edit 2: Upon further reading of the above link, it seems that you can do...

CREATE TABLE targetDB.targetTable SELECT * FROM sourceTable

To copy the structure and data at once. Amazing. :o

This post was edited on 05-02-2006 at 06:20 PM by WDZ.
05-02-2006 06:13 PM
Profile PM Web Find Quote Report
Weyzza
Veteran Member
*****

Avatar
SoCal sunset > *

Posts: 1170
Reputation: 29
– / Male / –
Joined: May 2003
O.P. RE: Copying database
It works :p

I didn't know that I could use INSERT INTO.
So, I'm guessing that I can append the target table using the same query.
I can or I can't?

Answer: yes.

This post was edited on 05-02-2006 at 06:29 PM by Weyzza.
Registered 7647 days, 14 hours, 26 minutes, 10 seconds ago.
Happy Birthday, WDZ

05-02-2006 06:22 PM
Profile PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: Copying database
quote:
Originally posted by thekid
So, I'm guessing that I can append the target table using the same query.
Yeah, sure, but keep in mind that you might have problems with duplicate rows/keys. Read the info in the manual about ON DUPLICATE KEY UPDATE and the IGNORE keyword.

This post was edited on 05-02-2006 at 06:33 PM by WDZ.
05-02-2006 06:32 PM
Profile PM Web Find Quote Report
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: Copying database
Hi,

You can't quite copy a database consisting of multiple tables with a single query, but you can do it with a single shell command.  Look here, under the heading "Using mysqldump to copy databases", toward the bottom of the page.

This post was edited on 05-02-2006 at 06:38 PM by Adeptus.
05-02-2006 06:36 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On