Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Updating MySQL database
Old 05-14-2008, 09:31 AM Updating MySQL database
Average Talker

Posts: 16
Name: Richard
Trades: 0
Hi All

Can I ask how best to update one MySQL database from another. Both databases use the same tables as they are from the same shopping cart though the content is somewhat different.

DROP TABLE IF EXISTS cscart_access_restriction_emailcc;
CREATE TABLE `cscart_access_restriction_emailcc` (
`item_id` int(11) unsigned NOT NULL auto_increment,
`value` varchar(66) NOT NULL default '',
`type` char(3) NOT NULL default '',
`avail` char(1) NOT NULL default 'Y',
`timestamp` int(11) NOT NULL default '0',
PRIMARY KEY (`item_id`),
KEY `type` (`type`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=latin1;

To merge the two would i use the statement UPDATE tables instead of DROP TABLE IF EXISTS something like this

UPDATE tables cscart_access_restriction_emailcc;
CREATE TABLE `cscart_access_restriction_emailcc` (
`item_id` int(11) unsigned NOT NULL auto_increment,
`value` varchar(66) NOT NULL default '',
`type` char(3) NOT NULL default '',
`avail` char(1) NOT NULL default 'Y',
`timestamp` int(11) NOT NULL default '0',
PRIMARY KEY (`item_id`),
KEY `type` (`type`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=latin1;



Thanks in advance
Demon Templates is offline
Reply With Quote
View Public Profile Visit Demon Templates's homepage!
 
 
Register now for full access!
Old 05-14-2008, 10:01 AM Re: Updating MySQL database
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
it don't work that way...
When you make an update, you have to tell which column and which row(s) you want to update.
Code:
update {table} set {col}={value} where {key}={key_value}
In my opinion, what you need here is an insert into query.
This is a ms sql server 2000/2005 syntax, I don't know how it would react on another database:
Code:
insert into cscart_access_restriction_emailcc
select *
from cscart_access_restriction_emailcc
But of course you are bound to run into problems...

The item_id will certainly conflict between the 2 databases, and you cannot update them blindly, as for sure there are relations put between the data in the item table and those in your access_restriction table.

Simply put, there is no simple, easy and conflict free road to do what you need to do. You will need to write a script that will read each line of the new database, and insert it in the correct tables, with the good referential keys maintained.

Trivial if you have realized the schema yourself. Infernal if you have to understand every relationship and don't have any infos...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-15-2008, 03:10 PM Re: Updating MySQL database
Average Talker

Posts: 23
Trades: 0
According to your scenario, it is not possible to merge 2 databases with simple SQL queries. You must have to write a script which will merge databases while maintaining integrity as tripy mentioned.
__________________

Please login or register to view this content. Registration is FREE
mwasif is offline
Reply With Quote
View Public Profile Visit mwasif's homepage!
 
Reply     « Reply to Updating MySQL database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43637 seconds with 12 queries