Sql Server:使用“强制外键约束”的好处是什么?当它设置为“否”时 [英] Sql Server: What is the benefit of using "Enforce foreign key constraint" when it's set to "NO"?

查看:444
本文介绍了Sql Server:使用“强制外键约束”的好处是什么?当它设置为“否”时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道RDBMS中强制执行外键约束的目的。但是在设置为否时有什么好处吗?

解决方案

在正常生产中,此设置应 / strong>设置为 NO



但是:当您开发或重组数据库时,或当你做例如您需要清理(清理)大量的大量数据,因此关闭外键约束可以将非有效数据加载到表中是有意义的。当然,正如我所说 - 你不应该长时间关闭这个设置 - 你应该继续清理数据,删除那些违反FK约束的行,或者更新它们的值所以他们匹配一个父行。



再次:在正常生产模式下,此设置不应该是 NO - 但是对于特定的任务,它可能有助于更容易地完成工作。请谨慎使用,并尽快将FK约束重新开启!


I know the purpose of "Enforce foreign key constraint" in RDBMS. But is there any benefit when it's set to "NO" ?

解决方案

In normal production, this setting should never be set to NO.

But: when you're developing, or restructuring a database, or when you do e.g. a large bulk load of data that you'll need to "sanitize" (clean up), then it can make sense to turn off foreign key constraints to allow "non-valid" data to be loaded into a table. Of course, as I said - you shouldn't keep that setting turned off for a long period of time - you should then proceed to clean up the data, either delete those rows that are in violation of the FK constraint, or update their values so they match a parent row.

So again: in "normal" production mode, this setting should never be NO - but for specific tasks, it might help get the job done more easily. Use it with caution, and always turn the FK constraints back on as soon as you can!

这篇关于Sql Server:使用“强制外键约束”的好处是什么?当它设置为“否”时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆