Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. synchronization of two databases

synchronization of two databases

Scheduled Pinned Locked Moved Database
databasequestionsysadmin
10 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Vrinceanu
    wrote on last edited by
    #1

    Hi, I have two identical databases   whitch are different only by name (DB1 and DB2) Eatch database is on one computer (PC1 and PC2) into a network. Database DB1 contains table Tab1. Database DB2 contains table Tab2. The two tables Tab1 and Tab2 are identical as structure an receive the same data from an external aplication. There are moments when the network is interrupted, from different causes and the two tables no longer contains the same data. To synchronize the tables I have to copy only the rows which are lost from Tab1 in Tab2. By a stored procedure i have to know which are the numbers of rows lost from Tab2 to fill in with rows from Tab1 I actually have to copy a number of lines from Tab1 in Tab2 with the condition to know which are the rows lost from Tab2. Someone knows how can I do that? Thanks.

    S B D R 4 Replies Last reply
    0
    • R Robert Vrinceanu

      Hi, I have two identical databases   whitch are different only by name (DB1 and DB2) Eatch database is on one computer (PC1 and PC2) into a network. Database DB1 contains table Tab1. Database DB2 contains table Tab2. The two tables Tab1 and Tab2 are identical as structure an receive the same data from an external aplication. There are moments when the network is interrupted, from different causes and the two tables no longer contains the same data. To synchronize the tables I have to copy only the rows which are lost from Tab1 in Tab2. By a stored procedure i have to know which are the numbers of rows lost from Tab2 to fill in with rows from Tab1 I actually have to copy a number of lines from Tab1 in Tab2 with the condition to know which are the rows lost from Tab2. Someone knows how can I do that? Thanks.

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi Do you rows have an unique identifier? If yes you could use something like this: insert into tab2 select * from tab1 where not exists (select table2.id from tab2 as table2 where table2.id = tab1.id) This will only work for added rows. Changing existing rows and synchronizing deleted rows will not work with this. Regards Sebastian

      It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

      1 Reply Last reply
      0
      • R Robert Vrinceanu

        Hi, I have two identical databases   whitch are different only by name (DB1 and DB2) Eatch database is on one computer (PC1 and PC2) into a network. Database DB1 contains table Tab1. Database DB2 contains table Tab2. The two tables Tab1 and Tab2 are identical as structure an receive the same data from an external aplication. There are moments when the network is interrupted, from different causes and the two tables no longer contains the same data. To synchronize the tables I have to copy only the rows which are lost from Tab1 in Tab2. By a stored procedure i have to know which are the numbers of rows lost from Tab2 to fill in with rows from Tab1 I actually have to copy a number of lines from Tab1 in Tab2 with the condition to know which are the rows lost from Tab2. Someone knows how can I do that? Thanks.

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        Use this: Case 1 Insert into DB1.dbo.Table1 select * DB2.dbo.Table2 from where DB2.dbo.Table2.ID not in (select DB1.dbo.Table1.ID from DB1.dbo.Table1 ) Case 2: Insert into DB2.dbo.Table2 select * DB1.dbo.Table1 from where DB1.dbo.Table1.ID not in (select DB2.dbo.Table2.ID from DB2.dbo.Table2)


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

        R 1 Reply Last reply
        0
        • B Blue_Boy

          Use this: Case 1 Insert into DB1.dbo.Table1 select * DB2.dbo.Table2 from where DB2.dbo.Table2.ID not in (select DB1.dbo.Table1.ID from DB1.dbo.Table1 ) Case 2: Insert into DB2.dbo.Table2 select * DB1.dbo.Table1 from where DB1.dbo.Table1.ID not in (select DB2.dbo.Table2.ID from DB2.dbo.Table2)


          I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

          R Offline
          R Offline
          Robert Vrinceanu
          wrote on last edited by
          #4

          Thank you all. The problem is that databases DB1 and DB2 are on different computers.

          L 1 Reply Last reply
          0
          • R Robert Vrinceanu

            Hi, I have two identical databases   whitch are different only by name (DB1 and DB2) Eatch database is on one computer (PC1 and PC2) into a network. Database DB1 contains table Tab1. Database DB2 contains table Tab2. The two tables Tab1 and Tab2 are identical as structure an receive the same data from an external aplication. There are moments when the network is interrupted, from different causes and the two tables no longer contains the same data. To synchronize the tables I have to copy only the rows which are lost from Tab1 in Tab2. By a stored procedure i have to know which are the numbers of rows lost from Tab2 to fill in with rows from Tab1 I actually have to copy a number of lines from Tab1 in Tab2 with the condition to know which are the rows lost from Tab2. Someone knows how can I do that? Thanks.

            D Offline
            D Offline
            David Skelly
            wrote on last edited by
            #5

            http://www.sqlaccessories.com/SQL_Data_Examiner/[^]

            1 Reply Last reply
            0
            • R Robert Vrinceanu

              Thank you all. The problem is that databases DB1 and DB2 are on different computers.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              What brand are DB1 and DB2? If it's SQL Server, you could add a linked server[^] :)

              1 Reply Last reply
              0
              • R Robert Vrinceanu

                Hi, I have two identical databases   whitch are different only by name (DB1 and DB2) Eatch database is on one computer (PC1 and PC2) into a network. Database DB1 contains table Tab1. Database DB2 contains table Tab2. The two tables Tab1 and Tab2 are identical as structure an receive the same data from an external aplication. There are moments when the network is interrupted, from different causes and the two tables no longer contains the same data. To synchronize the tables I have to copy only the rows which are lost from Tab1 in Tab2. By a stored procedure i have to know which are the numbers of rows lost from Tab2 to fill in with rows from Tab1 I actually have to copy a number of lines from Tab1 in Tab2 with the condition to know which are the rows lost from Tab2. Someone knows how can I do that? Thanks.

                R Offline
                R Offline
                Robin_Roy
                wrote on last edited by
                #7

                Which database engine are you using. If you are using MS-SQL Server, it is fairly simple using linked server to keep both the dB in sync using some simple queries and statements...

                R D 2 Replies Last reply
                0
                • R Robin_Roy

                  Which database engine are you using. If you are using MS-SQL Server, it is fairly simple using linked server to keep both the dB in sync using some simple queries and statements...

                  R Offline
                  R Offline
                  Robert Vrinceanu
                  wrote on last edited by
                  #8

                  Yes, DB1 is MSSQL 2005 and DB2 is MSSQL2000. I haven't experience with "linked server" Can you indicate some examples. Thanks. Regards, Robert

                  R 1 Reply Last reply
                  0
                  • R Robert Vrinceanu

                    Yes, DB1 is MSSQL 2005 and DB2 is MSSQL2000. I haven't experience with "linked server" Can you indicate some examples. Thanks. Regards, Robert

                    R Offline
                    R Offline
                    Robin_Roy
                    wrote on last edited by
                    #9

                    You can get good details from the following URL http://msdn.microsoft.com/en-us/library/aa213778(SQL.80).aspx Let me know, if you have any difficulty

                    1 Reply Last reply
                    0
                    • R Robin_Roy

                      Which database engine are you using. If you are using MS-SQL Server, it is fairly simple using linked server to keep both the dB in sync using some simple queries and statements...

                      D Offline
                      D Offline
                      dingoishere
                      wrote on last edited by
                      #10

                      Try this to compare and sync two sql server database D-Softs Database Compare Tool

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups