Merging databases

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ike

    #1

    Merging databases

    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


  • Colin McKinnon

    #2
    Re: Merging databases

    Ike spilled the following:
    [color=blue]
    > 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?[/color]

    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.

    Comment

    • Colin McKinnon

      #3
      Re: Merging databases

      Ike spilled the following:
      [color=blue]
      > 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?[/color]

      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.

      Comment

      • Colin McKinnon

        #4
        Re: Merging databases

        Ike spilled the following:
        [color=blue]
        > 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?[/color]

        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.

        Comment

        • Mike Chirico

          #5
          Re: Merging databases


          "Ike" <rxv@hotmail.co m> wrote in message
          news:LZzhc.5515 $e4.2113@newsre ad2.news.pas.ea rthlink.net...[color=blue]
          > Suppose I have a relational database, called "BranchA."
          >
          > I have a second relational database, of identical structure to BranchA,[/color]
          but[color=blue]
          > with different data, and this one is called BranchB.
          >
          > Can I merge the two, into, say, a BranchC somehow on occassion?[/color]

          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:




          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_s ummary (
          pkey int(11) NOT NULL auto_increment,
          a int,
          b varchar(12),
          timeEnter timestamp(14),
          PRIMARY KEY (pkey)
          ) type=MERGE UNION(log_01,lo g_02) INSERT_METHOD=L AST;


          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


          Comment

          • Mike Chirico

            #6
            Re: Merging databases


            "Ike" <rxv@hotmail.co m> wrote in message
            news:LZzhc.5515 $e4.2113@newsre ad2.news.pas.ea rthlink.net...[color=blue]
            > Suppose I have a relational database, called "BranchA."
            >
            > I have a second relational database, of identical structure to BranchA,[/color]
            but[color=blue]
            > with different data, and this one is called BranchB.
            >
            > Can I merge the two, into, say, a BranchC somehow on occassion?[/color]

            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:




            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_s ummary (
            pkey int(11) NOT NULL auto_increment,
            a int,
            b varchar(12),
            timeEnter timestamp(14),
            PRIMARY KEY (pkey)
            ) type=MERGE UNION(log_01,lo g_02) INSERT_METHOD=L AST;


            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


            Comment

            • Mike Chirico

              #7
              Re: Merging databases


              "Ike" <rxv@hotmail.co m> wrote in message
              news:LZzhc.5515 $e4.2113@newsre ad2.news.pas.ea rthlink.net...[color=blue]
              > Suppose I have a relational database, called "BranchA."
              >
              > I have a second relational database, of identical structure to BranchA,[/color]
              but[color=blue]
              > with different data, and this one is called BranchB.
              >
              > Can I merge the two, into, say, a BranchC somehow on occassion?[/color]

              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:




              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_s ummary (
              pkey int(11) NOT NULL auto_increment,
              a int,
              b varchar(12),
              timeEnter timestamp(14),
              PRIMARY KEY (pkey)
              ) type=MERGE UNION(log_01,lo g_02) INSERT_METHOD=L AST;


              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


              Comment

              • Mike Chirico

                #8
                Re: Merging databases

                > CREATE TABLE BranchSUMMARY_s ummary (

                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,lo g_02) INSERT_METHOD=L AST;

                Regards,

                Mike Chirico


                Comment

                • Mike Chirico

                  #9
                  Re: Merging databases

                  > CREATE TABLE BranchSUMMARY_s ummary (

                  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,lo g_02) INSERT_METHOD=L AST;

                  Regards,

                  Mike Chirico


                  Comment

                  • Mike Chirico

                    #10
                    Re: Merging databases

                    > CREATE TABLE BranchSUMMARY_s ummary (

                    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,lo g_02) INSERT_METHOD=L AST;

                    Regards,

                    Mike Chirico


                    Comment

                    • Ike

                      #11
                      Re: Merging databases

                      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" <mchirico@comca st.net> wrote in message
                      news:QqCdnWtNM_ Cwihrd4p2dnA@co mcast.com...[color=blue]
                      >
                      > "Ike" <rxv@hotmail.co m> wrote in message
                      > news:LZzhc.5515 $e4.2113@newsre ad2.news.pas.ea rthlink.net...[color=green]
                      > > Suppose I have a relational database, called "BranchA."
                      > >
                      > > I have a second relational database, of identical structure to BranchA,[/color]
                      > but[color=green]
                      > > with different data, and this one is called BranchB.
                      > >
                      > > Can I merge the two, into, say, a BranchC somehow on occassion?[/color]
                      >
                      > 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_s ummary (
                      > pkey int(11) NOT NULL auto_increment,
                      > a int,
                      > b varchar(12),
                      > timeEnter timestamp(14),
                      > PRIMARY KEY (pkey)
                      > ) type=MERGE UNION(log_01,lo g_02) INSERT_METHOD=L AST;
                      >
                      >
                      > 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
                      >
                      >[/color]


                      Comment

                      • Ike

                        #12
                        Re: Merging databases

                        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" <mchirico@comca st.net> wrote in message
                        news:QqCdnWtNM_ Cwihrd4p2dnA@co mcast.com...[color=blue]
                        >
                        > "Ike" <rxv@hotmail.co m> wrote in message
                        > news:LZzhc.5515 $e4.2113@newsre ad2.news.pas.ea rthlink.net...[color=green]
                        > > Suppose I have a relational database, called "BranchA."
                        > >
                        > > I have a second relational database, of identical structure to BranchA,[/color]
                        > but[color=green]
                        > > with different data, and this one is called BranchB.
                        > >
                        > > Can I merge the two, into, say, a BranchC somehow on occassion?[/color]
                        >
                        > 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_s ummary (
                        > pkey int(11) NOT NULL auto_increment,
                        > a int,
                        > b varchar(12),
                        > timeEnter timestamp(14),
                        > PRIMARY KEY (pkey)
                        > ) type=MERGE UNION(log_01,lo g_02) INSERT_METHOD=L AST;
                        >
                        >
                        > 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
                        >
                        >[/color]


                        Comment

                        • Ike

                          #13
                          Re: Merging databases

                          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" <mchirico@comca st.net> wrote in message
                          news:QqCdnWtNM_ Cwihrd4p2dnA@co mcast.com...[color=blue]
                          >
                          > "Ike" <rxv@hotmail.co m> wrote in message
                          > news:LZzhc.5515 $e4.2113@newsre ad2.news.pas.ea rthlink.net...[color=green]
                          > > Suppose I have a relational database, called "BranchA."
                          > >
                          > > I have a second relational database, of identical structure to BranchA,[/color]
                          > but[color=green]
                          > > with different data, and this one is called BranchB.
                          > >
                          > > Can I merge the two, into, say, a BranchC somehow on occassion?[/color]
                          >
                          > 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_s ummary (
                          > pkey int(11) NOT NULL auto_increment,
                          > a int,
                          > b varchar(12),
                          > timeEnter timestamp(14),
                          > PRIMARY KEY (pkey)
                          > ) type=MERGE UNION(log_01,lo g_02) INSERT_METHOD=L AST;
                          >
                          >
                          > 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
                          >
                          >[/color]


                          Comment

                          • Virgil Green

                            #14
                            Re: Merging databases

                            "Mike Chirico" <mchirico@comca st.net> wrote in message
                            news:QqCdnWtNM_ Cwihrd4p2dnA@co mcast.com...[color=blue]
                            >
                            > "Ike" <rxv@hotmail.co m> wrote in message
                            > news:LZzhc.5515 $e4.2113@newsre ad2.news.pas.ea rthlink.net...[color=green]
                            > > Suppose I have a relational database, called "BranchA."
                            > >
                            > > I have a second relational database, of identical structure to BranchA,[/color]
                            > but[color=green]
                            > > with different data, and this one is called BranchB.
                            > >
                            > > Can I merge the two, into, say, a BranchC somehow on occassion?[/color]
                            >
                            > 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_s ummary (
                            > pkey int(11) NOT NULL auto_increment,
                            > a int,
                            > b varchar(12),
                            > timeEnter timestamp(14),
                            > PRIMARY KEY (pkey)
                            > ) type=MERGE UNION(log_01,lo g_02) INSERT_METHOD=L AST;[/color]

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

                            CREATE TABLE BranchSUMMARY_s ummary (
                            pkey int(11) NOT NULL auto_increment,
                            a int,
                            b varchar(12),
                            timeEnter timestamp(14),
                            PRIMARY KEY (pkey)
                            ) type=MERGE UNION(BranchA,B ranchB) INSERT_METHOD=L AST;

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

                            - Virgil


                            Comment

                            • Virgil Green

                              #15
                              Re: Merging databases

                              "Mike Chirico" <mchirico@comca st.net> wrote in message
                              news:QqCdnWtNM_ Cwihrd4p2dnA@co mcast.com...[color=blue]
                              >
                              > "Ike" <rxv@hotmail.co m> wrote in message
                              > news:LZzhc.5515 $e4.2113@newsre ad2.news.pas.ea rthlink.net...[color=green]
                              > > Suppose I have a relational database, called "BranchA."
                              > >
                              > > I have a second relational database, of identical structure to BranchA,[/color]
                              > but[color=green]
                              > > with different data, and this one is called BranchB.
                              > >
                              > > Can I merge the two, into, say, a BranchC somehow on occassion?[/color]
                              >
                              > 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_s ummary (
                              > pkey int(11) NOT NULL auto_increment,
                              > a int,
                              > b varchar(12),
                              > timeEnter timestamp(14),
                              > PRIMARY KEY (pkey)
                              > ) type=MERGE UNION(log_01,lo g_02) INSERT_METHOD=L AST;[/color]

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

                              CREATE TABLE BranchSUMMARY_s ummary (
                              pkey int(11) NOT NULL auto_increment,
                              a int,
                              b varchar(12),
                              timeEnter timestamp(14),
                              PRIMARY KEY (pkey)
                              ) type=MERGE UNION(BranchA,B ranchB) INSERT_METHOD=L AST;

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

                              - Virgil


                              Comment

                              Working...