问题
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