How do you sync databases using ms sync framework when tables are using identity column and you need to match on an arbitrary key

若如初见. 提交于 2019-12-20 04:07:20

问题


Sorry for the long and confused title.

I have a customer that wants to sync three database. (Later it could be more.) All data in all three databases must sync to the all others. This does not at all need to be real time but would probably run nightly or something like that.

This database is using identity columns as primary/foreign keys.

The issue is that a given record could be added independently into two (or even more) of the databases but be the same data. So, for example, I could have a customer name John Smith of 123 Main Street created at both of the site databases. In this case I would want to FirstName LastName and the first 8 characters of the address (or maybe a phone number) to form the "match key" for merging records instead of adding new ones every time. In other words, after all of the syncronization is complete, I would want all 3 database to have just ONE record for John SMith at 123 Main Street.

By the way, the way that I was thinking of doing this is having one "master" database hosted in the cloud. All three databases would do a 2-way sync to this master database.

My main question is how would you get this to work? How do you define the "match key" for tables in the database. Is it as simple as creating unique constraints on the match keys? Is there a way to do it without changing the DB schema? (I am wiling to consider this but I the database is 3rd party and subject to change.)

Seth


回答1:


if you can add an extra column, create a new column based on the "match key" you specified above. Then configure Sync framework to use that column as the PK and ignoring the actual PKs in the table.

the approach should be similar to this post:

Part 3 – Synchronizing tables where Client and Server Primary Keys are different



来源:https://stackoverflow.com/questions/7184372/how-do-you-sync-databases-using-ms-sync-framework-when-tables-are-using-identity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!