Relationships between tables from different databases

北慕城南 提交于 2019-12-06 07:01:30

问题


Is it possible to define relationships between tables in different databases in SQL server 2008? And can you recommend an online tutorial for studying it? (I prefer ASP.NET, C#)


回答1:


No, you can't have foreign keys between databases.

Data integrity is within a single database only. If you need transactional consistency across databases then you should use a single database. The main issue is backups/restores: you will end up with broken data after a restore because your backups are not consistent.

A recent blog article "One Database or Ten?" explains in more details

Saying that, you can use triggers if you need this and are prepared to have broken data




回答2:


Yes you can but NOT using FOREIGN KEYS:

  1. You can use specific stored procs, which checks the consistency - in this case you have to make the user to use only these procedures for all the CRUD operations in both DBS

  2. Triggers, which will check the same

  3. All of the above have to run within properly isolated transaction to be sure, that your "just checked" values will not be deleted in a moment



来源:https://stackoverflow.com/questions/8561412/relationships-between-tables-from-different-databases

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