Sql-server – Inserting data into table in server B whenever table in server A gets updated

replicationsql servertrigger

I want to synchronize data from table 1 in server A to tables 2 and 3 in server B, whenever table 1 gets updated.

Tables from server A are not related to tables from server B, so I'd have to specify which columns in table 1 correspond to which columns in tables 2 and 3, and perhaps do some sort of operation on that data.

Server A, Table Y

Name  | Country | Sales  
Oscar | Peru    | 5000

Server B, Table X

Name  | Region | Amount | Currency | Multiplier | TotalAmount  
Oscar | Peru   | 5000   | €        | 5          | 25000 (=5000*5)

The goal here is to insert the record from server A to the table X in server B.

  • The 'Name' field maps to the 'Name' field
  • The 'Country' field maps to the 'Region' field
  • The 'Sales' field maps to the 'Amount' field
  • The 'Currency' field in server B will always be €
  • The 'Multiplier' field would be retrieved from another table in server B
  • The 'TotalAmount' field would be the result of Amount * Multiplier

Would this be possible to automate? Is using triggers the way to go?

I'm using SQL Server (and SMSS). The sync doesn't need to be instantaneous, it could take up to 10 or 20 minutes. The two servers are already linked. Server B is not used just for read only queries.

Best Answer

Normally you would use materialized views for sync'ing tables, however your table structures are different which probably rules out this solution. The next solution would be to implement insert/update/delete triggers on your source table. This can cause performance bottlenecks on high volume transactions. The third solution is to implement ETL (extract/transform/load). There are a number of commercial and open source solutions. Informatica, GoldenGate from Oracle are a couple of commercial options, Telend, Jaspersoft ETL, KETL are great open source. http://www.butleranalytics.com/30-etl-tools/ has a list and links to some ETL tools.