473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Merging databases

Ike
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA, but
with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?

Thanks, Ike
Jul 20 '05 #1
15 2898
Ike spilled the following:
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA,
but with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


This kinda suggests that you didn't normalize your database.

To answer your question....

1) do you need to ....
(
SELECT 'A' AS Branch, BranchA.* FROM BranchA WHERE $criteria
) UNION (
SELECT 'B' AS Branch, BranchB.* FROM BranchB WHERE $creiteria
)
2) if you really have to then...
DELETE FROM BranchToT;
INSERT INTO BranchToT SELECT * FROM BranchA WHERE $criteria
REPLACE INTO BranchToT SELECT * FROM BranchB WHERE $criteria
I'll leave you to work out why the third statement in the above might work
better with a REPLACE instead of an INSERT.

C.

Jul 20 '05 #2
Ike spilled the following:
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA,
but with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


This kinda suggests that you didn't normalize your database.

To answer your question....

1) do you need to ....
(
SELECT 'A' AS Branch, BranchA.* FROM BranchA WHERE $criteria
) UNION (
SELECT 'B' AS Branch, BranchB.* FROM BranchB WHERE $creiteria
)
2) if you really have to then...
DELETE FROM BranchToT;
INSERT INTO BranchToT SELECT * FROM BranchA WHERE $criteria
REPLACE INTO BranchToT SELECT * FROM BranchB WHERE $criteria
I'll leave you to work out why the third statement in the above might work
better with a REPLACE instead of an INSERT.

C.

Jul 20 '05 #3
Ike spilled the following:
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA,
but with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


This kinda suggests that you didn't normalize your database.

To answer your question....

1) do you need to ....
(
SELECT 'A' AS Branch, BranchA.* FROM BranchA WHERE $criteria
) UNION (
SELECT 'B' AS Branch, BranchB.* FROM BranchB WHERE $creiteria
)
2) if you really have to then...
DELETE FROM BranchToT;
INSERT INTO BranchToT SELECT * FROM BranchA WHERE $criteria
REPLACE INTO BranchToT SELECT * FROM BranchB WHERE $criteria
I'll leave you to work out why the third statement in the above might work
better with a REPLACE instead of an INSERT.

C.

Jul 20 '05 #4

"Ike" <rx*@hotmail.com> wrote in message
news:LZ****************@newsread2.news.pas.earthli nk.net...
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA, but with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


Yes, several tables can be merged into a summary table, and you can still
keep
BranchA, and BranchB...

See below or reference (TIP 8) at the following url:
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

CREATE TABLE BranchA (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchB (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;
insert into BranchA (a,b) values (1,'log1');
insert into BranchB (a,b) values (1,'log2');

To get combined results

select * from BranchSUMMARY;
Hope this helps.

Regards,

Mike Chirico
Jul 20 '05 #5

"Ike" <rx*@hotmail.com> wrote in message
news:LZ****************@newsread2.news.pas.earthli nk.net...
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA, but with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


Yes, several tables can be merged into a summary table, and you can still
keep
BranchA, and BranchB...

See below or reference (TIP 8) at the following url:
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

CREATE TABLE BranchA (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchB (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;
insert into BranchA (a,b) values (1,'log1');
insert into BranchB (a,b) values (1,'log2');

To get combined results

select * from BranchSUMMARY;
Hope this helps.

Regards,

Mike Chirico
Jul 20 '05 #6

"Ike" <rx*@hotmail.com> wrote in message
news:LZ****************@newsread2.news.pas.earthli nk.net...
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA, but with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


Yes, several tables can be merged into a summary table, and you can still
keep
BranchA, and BranchB...

See below or reference (TIP 8) at the following url:
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

CREATE TABLE BranchA (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchB (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;
insert into BranchA (a,b) values (1,'log1');
insert into BranchB (a,b) values (1,'log2');

To get combined results

select * from BranchSUMMARY;
Hope this helps.

Regards,

Mike Chirico
Jul 20 '05 #7
> CREATE TABLE BranchSUMMARY_summary (

That's BranchSUMMARY without "_summary" which was a typo on my part.

CREATE TABLE BranchSUMMARY (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;

Regards,

Mike Chirico
Jul 20 '05 #8
> CREATE TABLE BranchSUMMARY_summary (

That's BranchSUMMARY without "_summary" which was a typo on my part.

CREATE TABLE BranchSUMMARY (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;

Regards,

Mike Chirico
Jul 20 '05 #9
> CREATE TABLE BranchSUMMARY_summary (

That's BranchSUMMARY without "_summary" which was a typo on my part.

CREATE TABLE BranchSUMMARY (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;

Regards,

Mike Chirico
Jul 20 '05 #10
Ike
Ok, but, what if certain fields are links to other tables, which you are
merging as well? How do you know what to add to the fields (assuming these
keys are integers) -Ike

"Mike Chirico" <mc******@comcast.net> wrote in message
news:Qq********************@comcast.com...

"Ike" <rx*@hotmail.com> wrote in message
news:LZ****************@newsread2.news.pas.earthli nk.net...
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA,

but
with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


Yes, several tables can be merged into a summary table, and you can still
keep
BranchA, and BranchB...

See below or reference (TIP 8) at the following url:
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

CREATE TABLE BranchA (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchB (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;
insert into BranchA (a,b) values (1,'log1');
insert into BranchB (a,b) values (1,'log2');

To get combined results

select * from BranchSUMMARY;
Hope this helps.

Regards,

Mike Chirico

Jul 20 '05 #11
Ike
Ok, but, what if certain fields are links to other tables, which you are
merging as well? How do you know what to add to the fields (assuming these
keys are integers) -Ike

"Mike Chirico" <mc******@comcast.net> wrote in message
news:Qq********************@comcast.com...

"Ike" <rx*@hotmail.com> wrote in message
news:LZ****************@newsread2.news.pas.earthli nk.net...
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA,

but
with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


Yes, several tables can be merged into a summary table, and you can still
keep
BranchA, and BranchB...

See below or reference (TIP 8) at the following url:
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

CREATE TABLE BranchA (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchB (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;
insert into BranchA (a,b) values (1,'log1');
insert into BranchB (a,b) values (1,'log2');

To get combined results

select * from BranchSUMMARY;
Hope this helps.

Regards,

Mike Chirico

Jul 20 '05 #12
Ike
Ok, but, what if certain fields are links to other tables, which you are
merging as well? How do you know what to add to the fields (assuming these
keys are integers) -Ike

"Mike Chirico" <mc******@comcast.net> wrote in message
news:Qq********************@comcast.com...

"Ike" <rx*@hotmail.com> wrote in message
news:LZ****************@newsread2.news.pas.earthli nk.net...
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA,

but
with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


Yes, several tables can be merged into a summary table, and you can still
keep
BranchA, and BranchB...

See below or reference (TIP 8) at the following url:
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

CREATE TABLE BranchA (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchB (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;
insert into BranchA (a,b) values (1,'log1');
insert into BranchB (a,b) values (1,'log2');

To get combined results

select * from BranchSUMMARY;
Hope this helps.

Regards,

Mike Chirico

Jul 20 '05 #13
"Mike Chirico" <mc******@comcast.net> wrote in message
news:Qq********************@comcast.com...

"Ike" <rx*@hotmail.com> wrote in message
news:LZ****************@newsread2.news.pas.earthli nk.net...
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA,

but
with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


Yes, several tables can be merged into a summary table, and you can still
keep
BranchA, and BranchB...

See below or reference (TIP 8) at the following url:
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

CREATE TABLE BranchA (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchB (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;


I found this to be quite odd until I looked at your web reference to confirm
my suspicions:

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(BranchA,BranchB) INSERT_METHOD=LAST;

The original was will referring to log_x files from your examples at your
web site.

- Virgil
Jul 20 '05 #14
"Mike Chirico" <mc******@comcast.net> wrote in message
news:Qq********************@comcast.com...

"Ike" <rx*@hotmail.com> wrote in message
news:LZ****************@newsread2.news.pas.earthli nk.net...
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA,

but
with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


Yes, several tables can be merged into a summary table, and you can still
keep
BranchA, and BranchB...

See below or reference (TIP 8) at the following url:
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

CREATE TABLE BranchA (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchB (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;


I found this to be quite odd until I looked at your web reference to confirm
my suspicions:

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(BranchA,BranchB) INSERT_METHOD=LAST;

The original was will referring to log_x files from your examples at your
web site.

- Virgil
Jul 20 '05 #15
"Mike Chirico" <mc******@comcast.net> wrote in message
news:Qq********************@comcast.com...

"Ike" <rx*@hotmail.com> wrote in message
news:LZ****************@newsread2.news.pas.earthli nk.net...
Suppose I have a relational database, called "BranchA."

I have a second relational database, of identical structure to BranchA,

but
with different data, and this one is called BranchB.

Can I merge the two, into, say, a BranchC somehow on occassion?


Yes, several tables can be merged into a summary table, and you can still
keep
BranchA, and BranchB...

See below or reference (TIP 8) at the following url:
http://osdn.dl.sourceforge.net/sourc...ADME_mysql.txt

CREATE TABLE BranchA (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchB (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;


I found this to be quite odd until I looked at your web reference to confirm
my suspicions:

CREATE TABLE BranchSUMMARY_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(BranchA,BranchB) INSERT_METHOD=LAST;

The original was will referring to log_x files from your examples at your
web site.

- Virgil
Jul 20 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Patrick | last post by:
I have got 2 XML documents, both of which conform to the same XSD Schema, which define possible optional elements. The 2 XML documents contain 2 disjoint set of XML elements. What is the best,...
3
by: abprules | last post by:
If I wanted to merge 2 sample databases that are from the same Access version, such as an events management and a scheduling database, is this possible? And if so, can anyone give me directions or...
1
by: actimel01 | last post by:
I know this question has been asked many times before but I can't find an answer that fits my data! I have two Access databases. The tables in each have the exactly the same fields except for one...
31
by: louishong | last post by:
3rd time posting this as the first two simply disappeared! Here's the issue: We currently run an Access application in the West Coast for tracking resource centric data. For those located in the...
1
by: Chandra | last post by:
I am storing data temporarily in a database... and periodically need to update that huge database, so just has to copy that temp DB to the original one. Using sql may take a few hours to finish...
3
by: Ralph Smith | last post by:
I have two identical databases on two different servers and I need to add the data in tables from one server to the tables in the other server. Is there a way to do that in mysql? thanks, Ralph
9
by: karenjfrancis | last post by:
I have 4 Access databases, all with the same data model but different data. I want to build a front end that brings all of the data in the 4 databases together into one. Assuming my table of...
6
by: gaubun | last post by:
Hi All, Just joined this site....I am really stuck into one problem. Actually I am writing a code in VB6 to merge TWO ACCESS DATABASES. Wanted to know if I can use a single sql query to merge. Is...
3
by: ramab | last post by:
Hi, im trying to merge 2 databases having the same structure. How do i merge the two databases which have unique identifiers and auto numbers. e.g the first 10 records in table A , it will have auto...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.