what are the advantages of defining a foreign key(定义外键有什么好处)
问题描述
在使用处理关系的 MVC 框架时定义外键有什么好处?
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.
这篇关于定义外键有什么好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:定义外键有什么好处


- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- SQL 临时表问题 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01