What's the best way to ensure referential integrity on a replicated database?

此生再无相见时 提交于 2020-01-15 11:51:51

问题


Using SQL SERVER 2005, I have a couple of questions on Replication and referential integrity.

1) Does Replication handle referential integrity?

2) If I do an Insert to Parent table and then to Insert to Child table, in one transaction, on Source DB - will Replicated DB also behave in the same manner? I.e. In Replicated DB record must be present in Master table, before it is referenced in child table?

Thanks


回答1:


Assuming replication is transactional and you have referential integrity on your publisher, then any subscribers will be in sync and therefore referential integrity will be maintained. The order of inserts is consistent.




回答2:


Using replication will not guarantee you referential integrity

Referential integrity is mainted when a row is deleted from the primary table and the record still exists in its foreign key table where it is refrenced

Using primary key and foreign key will guarantee it and just for additional information there are comand like "ON DELETE CASCADE" will delete the key from primary if deleted from foreign key



来源:https://stackoverflow.com/questions/9366153/whats-the-best-way-to-ensure-referential-integrity-on-a-replicated-database

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