SQL Server - synchronizing 2 tables on 2 different databases

前端 未结 3 910
-上瘾入骨i
-上瘾入骨i 2020-12-13 03:04

I have 2 tables with same schema on 2 different databases on the same server with SQL Server 2008 R2. One table gets updated with data more often.

Now there is a nee

3条回答
  •  萌比男神i
    2020-12-13 03:19

    You can select from the different databases and use a cursor to loop the selected data. Within that cursor you can do some logic and update or delete from the target table.

    Also SQL 2008 has a nice new MERGE statement which you can use to select/insert/update in one T-SQL query. http://technet.microsoft.com/en-us/library/bb510625%28v=sql.105%29.aspx

    For more complex processes i use the first option. For more straight forward sync tasks i use the second option.

    As an extra option there is also Server Integration Services (SSIS): http://blogs.msdn.com/b/jorgepc/archive/2010/12/07/synchronize-two-tables-using-sql-server-integration-services-ssis-part-i-of-ii.aspx

提交回复
热议问题