本文介绍了您是否绝对需要数据库中的外键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道外键在数据库中到底有多有用。本质上,如果开发人员知道不同表依赖的键,他们可以像有外键一样编写查询,对吧?

I was wondering how useful foreign keys really are in a database. Essentially, if the developers know what keys the different tables depend on, they can write the queries just as though there was a foreign key, right?

此外,我确实看到了外键约束如何帮助防止各种数据完整性错误,但是例如说,程序员在保持数据完整性方面做得很好,外键真的有必要吗?

Also, I do see how to foreign-key constraints help prevent all sorts of bugs with data integrity, but say for example, the programmers do a good job of preserving data integrity, how necessary are foreign keys really?

推荐答案

如果您不在乎引用完整性,那么您是对的。但是....您应该关心参照完整性。

If you don't care about referential integrity then you are right. But.... you should care about referential integrity.

问题是人们会犯错误。电脑没有。

The problem is that people make mistakes. Computers do not.

关于您的评论:

有人最终会犯错。没有人是完美的。另外,如果您带来新来的人,则不一定总能确定他们编写完美代码的能力。

Someone will eventually make a mistake. No one is perfect. Also if you bring someone new in you aren't always sure of their ability to write "perfect" code.

此外,您还会失去级联删除的能力以及已定义外键的许多其他功能。

In addition to that you lose the ability to do cascading deletes and a number of other features that having defined foreign keys allow.

这篇关于您是否绝对需要数据库中的外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 20:04