数据库关系 [英] database relationships

查看:168
本文介绍了数据库关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中设置正确的关系有助于数据完整性以外的任何其他操作吗?

does setting up proper relationships in a database help with anything else other than data integrity?

它们是否会改善或阻碍性能?

do they improve or hinder performance?

推荐答案

我不得不说,正确的关系将帮助人们更好地理解数据(或数据的意图),比忽略它们更好,特别是整体成本维持不起来相当低。

I'd have to say that proper relationships will help people to understand the data (or the intention of the data) better than if omitting them, especially as the overall cost is quite low in maintaining them.

它们的存在并不妨碍性能,除非在架构方面(如其他人所指出的,数据完整性偶尔会导致外键冲突,可能有一些效果),但恕我直言(如果使用正确)。

Their presence doesn't hinder performance except in terms of architecture (as others have pointed out, data integrity will occasionally cause foreign key violations which may have some effect) but IMHO is outweighed by the many benefits (if used correctly).

我知道你不是问是否使用FKs,但我想我只是添加一个关于为什么使用它们的观点的几个观点(并且必须处理后果):

I know you weren't asking whether to use FKs or not, but I thought I'd just add a couple of viewpoints about why to use them (and have to deal with the consequences):

还有其他考虑,例如如果你计划使用ORM或许以后)你需要外键。它们也可以对ETL /数据导入和导出非常有用,以后用于报告和数据仓库。

There are other considerations too, such as if you ever plan to use an ORM (perhaps later on) you'll require foreign keys. They can also be very helpful for ETL/Data Import and Export and later for reporting and data warehousing.

如果其他应用程序使用模式,外键实现一个基本的业务逻辑。所以你的应用程序(和任何其他人)只需要知道关系(并尊重他们)。它会保持数据一致,最有可能减少任何消费应用程序中的数据错误的数量。

It's also helpful if other applications will make use of the schema - since Foreign Keys implement a basic business logic. So your application (and any others) only need to be aware of the relationships (and honour them). It'll keep the data consistent and most likely reduce the number of data errors in any consuming applications.

最后,它给你一个很好的提示,索引 - 因为它很可能你将通过FK值查找表数据。

Lastly, it gives you a pretty decent hint as to where to put indexes - since it's likely you'll lookup table data by an FK value.

这篇关于数据库关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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