当前位置:网站首页>浅谈数据库设计之三大范式
浅谈数据库设计之三大范式
2022-04-23 20:39:00 【小简(JanYork)】
我的博客https://www.ideaopen.cn/
范式?
即规范!
*范式是“符合某一种级别的关系模式的集合,表示一个关系内部各属性之间的联系的合理化程度”。 *很晦涩吧?实际上你可以把它粗略地理解为一张数据表的表结构所符合的某种设计标准的级别。
数据库范式也分为1NF,2NF,3NF,BCNF,4NF,5N
一般在我们设计关系型数据库的时候,最多考虑到BCNF
就够。
符合高一级范式的设计,必定符合低一级范式,例如符合
2NF
的关系模式,必定符合1NF
。
1NF
-第一范式
数据表的每一列都要保持它的原子特性,也就是列不能再被分割。
比如这样:
进货它还可以被分出进货的数量,进货的单价等等属性。所以这样是不符合第一范式的。
2NF
-第二范式
第二范式(
2NF
)是在第一范式(1NF
)的基础上建立起来的,即满足第二范式(2NF
)必须先满足第一范式(1NF
)。
- 即满足第一范式前提,当存在多个主键的时候,才会发生不符合第二范式的情况!!!。
- 比如有两个主键,不能存在这样的属性,它只依赖于其中一个主键,这就是不符合第二范式。
- 通俗理解是任意一个字段都只依赖表中的同一个字段。
依赖
在数据表中,属性(属性组)X确定的情况下,能完全退出来属性Y完全依赖于X。
完全依赖
完全依赖是针对于属性组来说,当一组属性X能推出来Y的时候就说Y完全依赖于X。
部分依赖
一组属性X中的其中一个或几个属性能推出Y就说Y部分依赖于X。
3NF
-第三范式
首先,要满足第三范式(3NF
)必须先满足第二范式(2NF
)。
也就是说,要求一个数据库表中不包含已在其它表中已包含的非主键字段。
三范式一定需要?
我们的三范式是一般规范。就是说,只是一般都会遵守这个规范。
但是!!!不是一定需要遵守,比如有时候,数据不冗余也不是好事。所以,我们要根据需要来定义,建立在需求之上。
没有冗余的数据库未必是最好的数据库,有时为了提高运行效率,提高读性能,就必须降低范式标准,适当保留冗余数据。
其他范式
BCNF
-BC范式
关系模式R<U,F>中,若每一个决定因素都包含码,则R<U,F>属于BCFN
。
即:
- 所有非主属性对每一个码都是完全函数依赖;
- 所有主属性对每一个不包含它的码也是完全函数依赖;
- 没有任何属性完全函数依赖于非码的任何一组属性。
4NF
-第四范式
限制关系模式的属性之间不允许有非平凡且非函数依赖的多值依赖。
5NF
-第五范式
- 必须满足第四范式。
- 表必须可以分解为较小的表,除非那些表在逻辑上拥有与原始表相同的主键。
一般在我们设计关系型数据库的时候,最多考虑到
BCNF
就够。!!!
版权声明
本文为[小简(JanYork)]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_60750453/article/details/124304928
边栏推荐
- Solution: NPM err! code ELIFECYCLE npm ERR! errno 1
- [matlab 2016 use mex command to find editor visual studio 2019]
- 16MySQL之DCL 中 COMMIT和ROllBACK
- Bracket matching -- [implementation of one-dimensional array]
- Syntaxerror: unexpected token r in JSON at position 0
- LeetCode 74、搜索二维矩阵
- Introduction to intrusion detection data set
- Latex formula
- C migration project record: modify namespace and folder name
- Rt-1052 learning notes - GPIO architecture analysis
猜你喜欢
Devaxpress report replay: complete the drawing of conventional two-dimensional report + histogram + pie chart
[stack and queue topics] - sliding window
The ODB model calculates the data and outputs it to excel
Monte Carlo py solves the area problem! (save pupils Series)
[graph theory brush question-5] Li Kou 1971 Find out if there is a path in the graph
GO語言開發天天生鮮項目第三天 案例-新聞發布系統二
Unity animation creates sequence frame code and generates animationclip
LeetCode 74、搜索二维矩阵
C migration project record: modify namespace and folder name
Linux64Bit下安装MySQL5.6-不能修改root密码
随机推荐
How do BIM swindlers cheat? (turn)
Introduction to intrusion detection data set
[SQL] string series 2: split a string into multiple lines according to specific characters
I JS deep copy and shallow copy
Commit and rollback in DCL of 16 MySQL
三十.什么是vm和vc?
内网渗透之DOS命令
Summary and effect analysis of methods for calculating binocular parallax
BMP JPEG picture to vector image contourtrace
How can matlab obtain the truncated image in trainingimagelabeler
Syntax Error: TypeError: this. getOptions is not a function
ABAQUS script email auto notification
How to configure SSH public key in code cloud
bounding box iou
【PTA】L2-011 玩转二叉树
"Meta function" of tidb 6.0: what is placement rules in SQL?
居家第二十三天的午饭
Flex layout
CONDA environment management command
Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high