Synchronizing Database

Hi,

I have application that use SQL server database in local network, and I have remote network that has same database structure and I want to synchronize data.

I have problem how to know deleted rows and added rows in the database.

I little other words:

Updated rows -> Normal updating using table primary key and depending on modify date.

Deleted rows -> Normal deleting using table primary key but how can I now if the rows is deleted or new .

Added rows -> Normal adding, but how can I now if the row is new or deleted one

Note: I want to get merge data between both databases because all databases have users.

 

Regards



Answer this question

Synchronizing Database

  • sally_de

    Roger is right -unless you have some funky network connection between your databases your best option is to consider database replication

    see http://msdn2.microsoft.com/en-us/library/ms151827.aspx and http://www.replicationanswers.com/Default.asp

    Arnon



  • Henrik Karlsson

    Thank you.
    I'll try to use database replication.

  • shayc

    It's notclear to me what you're doing that isn't handled by normal SQL Server replications which would automatically handle all this for you. Replication uses a log reader or triggers depending on which type of replication you are using to capture the changes at one database and apply the same change to the replicated database. The log reader and the triggers obviously can figure out what command was used to change the master copy so it's easy to replicate it. If you can't use replication for some reason, you probably can't do log reading but you could use triggers and the contents of the Inserted and Deleted tables in the trigger should help you figure out what happened - a row in the inserted but not the deleted table is an insert. A row in the deleted but not the inserted is a delete and a row in both is an update. While this will work, it's a lot of work to do what replication will do for you already.
  • Synchronizing Database