Data Synchronization - write only new rows on target
mpetcov
Posts: 5 Bronze 2
I am attempting to sync data with the following options at table & column level (please assume that I am fully aware of the t-sql constrains on this):
1. Initial sync: assumes that the target is empty and writes all data;
2. Always: always sync the data from source to target;
3. New Rows Only: insert in target only the new rows from source(by primary key);
The code below should handle my inclusions (please correct me if I am wrong):
Now, for tables that should sync only new rows, how do I exclude the other differences?
I was expecting something in TableDifferences:
Thanks,
Mihai
1. Initial sync: assumes that the target is empty and writes all data;
2. Always: always sync the data from source to target;
3. New Rows Only: insert in target only the new rows from source(by primary key);
The code below should handle my inclusions (please correct me if I am wrong):
TableMappings mappings = new TableMappings(); mappings.Options = new EngineDataCompareOptions(MappingOptions.Default, ComparisonOptions.Default, SqlOptions.Default); mappings.CreateMappings(sourceScripts.Tables, targetDb.Tables); foreach (TableMapping mapping in mappings) { mapping.Include = true/false; foreach (var fieldMapping in mapping.FieldMappings) { filedMapping.Include = true/false; } }
Now, for tables that should sync only new rows, how do I exclude the other differences?
I was expecting something in TableDifferences:
TableDifferences diffs = session.TableDifferences; foreach (TableDifference diff in diffs) { //will it work in here? how? }
Thanks,
Mihai
Comments
Thanks for the question on the SQL Comparison SDK. For this you would have to look at the differences of the table comparison results and determine for the differences if the row existed only in source (a new row) or in both source and target (an update to an old row). Then only synch the rows which are new which would be differences that only exist in source. I don't believe we have a method that does this automatically but you could build the logic into your foreach loop.
Red Gate Software
US Product Support
I'm afraid you'll need to be a bit more specific.
Here is what I got so far:
Am I on the right track? How do I exclude those differences/rows?
So inside your loop in your initial forum post, you'd set SqlSynchronization to AddSql:
Redgate Software