当前位置:网站首页>Why do we seldom use foreign keys?
Why do we seldom use foreign keys?
2022-06-22 23:49:00 【Kunlunbase Kunlun database】
background
At present, many companies do not consider adding foreign keys , Many people don't use foreign keys much at work , After all, every time I do DELETE perhaps UPDATE Must consider foreign key constraints , It can lead to painful development , The test data is extremely inconvenient .
In my opinion , In the corresponding scenario , If you use a feature that does more harm than good , You may not choose . So whether to use foreign keys depends on the corresponding scenario , You can't abandon foreign keys completely .
Why do you rarely use foreign keys ?
There are some inconveniences in using foreign keys at present , That's why most people don't use it . I specifically summarized the following reasons :
1、 Increase database pressure
A foreign key is the implementation of a consistent transaction of data , All to the database server to complete , And you have foreign keys , As some additions involving foreign key fields 、 Delete 、 After update operation , You need to trigger related operations to check , Resources have to be consumed .
2、 The deadlock problem
If it is a high concurrency and high traffic transaction scenario , Using foreign keys can also cause deadlock .
3、 Development is not convenient
When there are foreign keys , Both development and maintenance , When data needs to be maintained manually , It's not very convenient , Consider cascading factors .
4、 Data brush Library
In the actual development process , It is inevitable to brush the library frequently , Import or delete data , The existence of a foreign key will cause the table deletion or insertion to fail ( Table data change has sequence requirements ).
5、 Foreign key maintenance
As the project iterates , The relationship between tables also changes , For example, a foreign key needs to be deleted ; Or to add a foreign key , However, due to the inaccuracy of the existing data , The foreign key cannot be added , in the course of time ,ER Graphs also do not completely show table relationships , this ER Picture or not ?
Are foreign keys really useless ?
Existence is reason , Every product , Since every function exists , There are also advantages in some places . The author summarizes several advantages of foreign keys :
1、 Database consistency
Data consistency is guaranteed by the database itself 、 Integrity will be more reliable , The program is difficult 100% Ensure data consistency 、 integrity , Using foreign keys, even when the database server crashes or other problems occur , It can also ensure the consistency and integrity of data to the greatest extent .
2、ER Figure reliability
Database design with main foreign key can increase ER Readability of graphs ( There are also special company products that pay special attention to this aspect ).
summary
1、 If it is a single machine with low concurrency , No performance tuning is required , Or the consistency of the data cannot be guaranteed by the program , integrity , You can use foreign keys , As in school , Ensure data consistency and integrity , The base number is not big .
2、 For high concurrency , Distributed , Make the system performance better , And better maintenance , Do not use foreign keys .
边栏推荐
- Learning the interpretable representation of quantum entanglement, the depth generation model can be directly applied to other physical systems
- 在一条DML语句中插入/更新/删除/获取几百万行数据,你会特别注意什么?
- 口令安全是什么意思?等保2.0政策中口令安全标准条款有哪些?
- 考过HCIP依然转行失败,职业网工最看重的到底是什么
- 昆仑分布式数据库Sequence功能及其实现机制
- 剑指 Offer 11. 旋转数组的最小数字
- Use smart doc to automatically generate interface documents
- [go] go modules GETTING STARTED
- [go] go array and slice (dynamic array)
- 从类、API、框架三个层面学习设计可复用软件的具体技术学习心得
猜你喜欢

10 Super VIM plug-ins, I can't put them down

事物系统的几种异常场景

Digital data depth | about software self-control, source code left, no code right

【GO】Go Modules入門

数据库每日一题---第20天:按日期分组销售产品

弱电转职业网工难不难?华为售前工程师分享亲身经历
![[STM32 skill] use the hardware I2C of STM32 Hal library to drive rx8025t real-time clock chip](/img/32/88321db57afb50ccc096d687ff9c41.png)
[STM32 skill] use the hardware I2C of STM32 Hal library to drive rx8025t real-time clock chip

反向代理HAProxy

Optimization - linear programming

使用GetX构建更优雅的Flutter页面结构
随机推荐
Php7.3 error undefined function simplexml_ load_ string()
c# sqlsugar,hisql,freesql orm框架全方位性能测试对比 sqlserver 性能测试
【首发】Redis系列2:数据持久化提高可用性
Unity: use ray to detect objects
【GO】Go Modules入门
[kubernetes series] overview of kubernetes
Reddit's discussion on lamda model: it is not stateless. It adopts a dual process. Compared with the way it edits Wikipedia, it doesn't matter whether it has feelings or not
Learning the interpretable representation of quantum entanglement, the depth generation model can be directly applied to other physical systems
web缓存技术
OJ每日一练——验证子串
ES5 Object的扩展方法//call、apply 和 bind
【GO】go语言interface
Bubble sort pointer
[arm] it is reported that horizontal display is set for LVDS screen of rk3568 development board
LeetCode_ Backtracking_ Dynamic programming_ Medium_ 131. split palindrome string
OJ daily practice - find the first character that only appears once
XML escape character cross reference table
JSBridge
【GO】Go数组和切片(动态数组)
flutter外包,承接flutter项目