Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-07-2013, 05:07 PM   PM User | #1
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
Can you Insert to 2 databases

Hey all,


Can you insert data into 2 databases at the same time?

Thanks, Slayer
SlayerACC is offline   Reply With Quote
Old 01-07-2013, 07:33 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,548
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Short answer: No.

Longer answer: Depends on what you mean by "at the same time." If you mean "truly simultaneously" the answer is still no. If you mean "within milliseconds of each other and with the whole thing wrapped in a single transaction so that is one insert fails the other will as well" then the answer is yes.

But you can't do it with a single SQL statement. You could do it by creating a stored procedure that would insert into one and then into the other. And do it all in a single TRANSACTION.

Curiosity: Why would you do this with two separate DATABASES? I can see doing it with separate TABLES in the same database, but it would be highly unusual to do this across two DBs.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-07-2013, 09:13 PM   PM User | #3
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
Thanks for the reply...


That is what I was hoping for...

I am looking at have one as a global database that serves to the website... but another that for current use that can be emptied...

What are your thoughts to this?


or is there a better way?

Slayer.
SlayerACC is offline   Reply With Quote
Old 01-07-2013, 09:25 PM   PM User | #4
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
The only reason I can think of for doing this would be to have one as a production database and another as the development database. But you don't have to query two databases, for that. Keep them separate and just code the pages to use one if in production, the other if in development.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Users who have thanked WolfShade for this post:
SlayerACC (01-08-2013)
Old 01-07-2013, 09:39 PM   PM User | #5
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
This is what the databases are..

database 1) Vehicle inventory... loaded by importing.

database 2) Vehicle Global database. loaded by importing.


I load the on vehicle inventory db (1) and then I want it to goto the global database db(2) to store in our db if the vehicle comes back to us for sale again.. I can pull it out via the vin # in the global db(2)

What would be the best procedure to have them import to both databases at the same time.. and if there is a better way I would love to know.


Thanks, S.
SlayerACC is offline   Reply With Quote
Old 01-07-2013, 10:56 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,548
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by SlayerACC View Post
I am looking at have one as a global database that serves to the website... but another that for current use that can be emptied...
??? I would think that the one for "current use" would be the one that you would indeed use to server the website.

Surely you want the most recent data to be served to the website?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
SlayerACC (01-08-2013)
Old 01-08-2013, 03:17 AM   PM User | #7
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
Yes you are correct..

I will be using the current.. as the main database.. and have the secondary db as the db that holds all the information for all of the vehicles that come into our locations.

the main database will be erased and readded on a weekly time frame based on the new arrivals.

So I hope this is a good way of doing so..

Slayer.
SlayerACC is offline   Reply With Quote
Old 01-08-2013, 03:20 AM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,529
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
It would be easier to drop and recreate specific tables on a weekly time frame and keep everything in the one database. That way the weekly job lists the tables to be cleared (which is easier than deleting and recreating a database) and everything else just accesses everything in the one database.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
SlayerACC (01-08-2013)
Old 01-08-2013, 03:51 AM   PM User | #9
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
So are you say this..


1 database..


1 table that can be emptied on a weekly or bi-weekly basis

and a 2nd table that stores all the data.

if yes>>

how would I go about inserting records to the 2 tables at the same time.

as I currently import with php a 55 record table on a weekly basis to the current table.. and would like to have it go to the now global table as well.

Now this only happens during the import process..

this wasy I have a global table that can have every record excluding duplilcates and another that I can use to empty for current data.

Slayer.
SlayerACC is offline   Reply With Quote
Old 01-08-2013, 04:01 AM   PM User | #10
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
Thanks everyone...

I have now got it working where I can import my CSV file to database tables.


Thanks..

Slayer.
SlayerACC is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:42 PM.


Advertisement
Log in to turn off these ads.