top of page

SQL transfer changes between 2 tables, mini-replication

I have 2 identical SQL servers, with identical I refer to schema and not data. What I need to do is get the same data in both.

This is simple replication and would imply pulling the data from Table 1 that is not in Table 2. You can beat around the bush and run a massive query with temp tables and stuff, or simply use EXCEPT

SELECT * FROM [Table1]
SELECT * FROM [Table2]

Just make sure you are referencing exactly the same columns with the select statement.

I wish there was more to it, but this is super easy. This query will select everything from Table1 expect what is in Table2.

This works very well in tables with no easy Primary Key like GUIDs and VARCHAR columns. Using EXCEPT I reduced execution times by around 90%. Of course your mileage may vary, my query was running across linked servers over a WAN.

#2005 #2008 #2012

1 view0 comments
bottom of page