问题描述
我们正在设计一个数据库,我需要在其中考虑一些 FK(外键)约束.但不限于正式的结构化和规范化.只有当它提供任何性能或可扩展性优势.
We're designing a database in which I need to consider some FK(foreign key)constraints. But it is not limited toformal structuring and normalization.We go for it only if it provides anyperformance or scalability benefits.
我一直在浏览一些有趣的文章并在谷歌上搜索实际的好处.以下是一些链接:
I've been going thru some interesting articles and googling for practical benefits. Here are some links:
http://www.mssqltips.com/tip.asp?tip=1296
我想了解更多关于 FK 的好处(除了正式的结构和著名的级联删除更新).
I wanted to know more about the benefits of FK (apart from the formal structuring and the famous cascaded deleteupdate).
FK 默认不被索引",那么在索引 FK 时有哪些注意事项?
FK are not 'indexed' by default so what are the considerations while indexing an FK?
如何处理映射为外键的可空字段 - 是否允许?
How to handle nullable fields which are mapped as foreign key - is this allowed?
除了索引之外,这是否有助于优化 SQL-Server 中的查询执行计划?
Apart from indexing, does this help in optimizing query-execution plans in SQL-Server?
我知道还有更多,但我更希望专家就此发表意见.请指导我.
I know there's more but I'd prefer experts speaking on this. Please guide me.
推荐答案
- 外键不提供性能或可扩展性优势.
- 外键强制参照完整性.如果有人试图从父表中错误地删除行,这可以通过引发错误来提供实际好处.
- 默认情况下不索引外键.您应该为外键列建立索引,因为这样可以避免在删除/更新父行时对子表进行表扫描.
- 您可以使外键列可为空并插入空值.
这篇关于SQL Server 外键约束的好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!