定义外键有什么好处? [英] what are the advantages of defining a foreign key

查看:189
本文介绍了定义外键有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在使用一个框架允许的关系数据库时,定义一个外键的优点是什么?模型定义与关系。因为外键是通过模型定义的,似乎外键是多余的。在管理开发中的应用程序的数据库时,编辑/删除使用外键的表是一个麻烦。



使用外键有什么好处我正在放弃使用它们的全部?

解决方案

具有约束的外键(在某些DB引擎中)为您提供数据完整性在低级别(数据库级别)。
这意味着您无法物理创建不符合关系的记录。
这只是一种更安全的方式。


What is the advantage of defining a foreign key when working with an MVC framework that handles the relation?

I'm using a relational database with a framework that allows model definitions with relations. Because the foreign keys are defined through the models, it seems like foreign keys are redundant. When it comes to managing the database of an application in development, editing/deleting tables that are using foreign keys is a hassle.

Is there any advantage to using foreign keys that I'm forgoing by dropping the use of them altogether?

解决方案

Foreign keys with constraints(in some DB engines) give you data integrity on the low level(level of database). It means you can't physically create a record that doesn't fulfill relation. It's just a way to be more safe.

这篇关于定义外键有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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