how to write T-SQL to compare and copy data?

Posted by George2 on Stack Overflow See other posts from Stack Overflow or by George2
Published on 2010-04-27T10:53:38Z Indexed on 2010/04/27 11:23 UTC
Read the original article Hit count: 195

Filed under:

Hello everyone,

I have two SQL Server 2008 Enterprise databases (on two machines), and one of the databases is master database and another database is slave database.

I want to transfer update from a table in source database to a table in destination database (two tables are of the same schema, both of them are using a single column as unique primary key). The transfer rule is (in short, the rule is keeping the destination database the same as source database because of the update of the source database),

  1. if there is a new row in source database but not in destination database, insert the row in destination database;
  2. if a row not exists in source database but exists in destination database, delete the row in destination database;
  3. if a row's content (i.e. columns other than primary key columns) changes in source database, update the new content into destination database.

thanks in advance, George

© Stack Overflow or respective owner

Related posts about sql-server-2008