当前位置:网站首页>浅谈数据库设计之三大范式
浅谈数据库设计之三大范式
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
边栏推荐
- How many hacking methods do you know?
- 打新债中签以后怎么办,网上开户安全吗
- Queue template code
- Case of the third day of go language development fresh every day project - news release system II
- 2021-09-02 unity project uses rider to build hot change project failure record of ilruntime
- Commit and ROLLBACK in DCL of 16mysql
- How do BIM swindlers cheat? (turn)
- Shanghai a répondu que « le site officiel de la farine est illégal »: l'exploitation et l'entretien négligents ont été « noirs » et la police a déposé une plainte
- 高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
- Recognition of high-speed road signs by Matlab using alexnet
猜你喜欢
Es error: request contains unrecognized parameter [ignore_throttled]
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
Scrapy教程 - (2)寫一個簡單爬蟲
Latest investigation and progress of building intelligence based on sati
The construction and use of Fortress machine and springboard machine jumpserver are detailed in pictures and texts
How to configure SSH public key in code cloud
Go language development Daily Fresh Project Day 3 Case - Press Release System II
A useless confession artifact
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case
JS arrow function user and processing method of converting arrow function into ordinary function
随机推荐
Leetcode 994, rotten orange
Leetcode 1346. Check whether integers and their multiples exist
Solve the Chinese garbled code of URL in JS - decoding
Parsing methods of JSON data in C - jar and jobobject: error reading jar from jsonreader Current JsonReader item
Some basic knowledge of devexpress report development
Leetcode 1351. Negative numbers in statistical ordered matrices
Recommend an open source free drawing software draw IO exportable vector graph
The construction and use of Fortress machine and springboard machine jumpserver are detailed in pictures and texts
Matlab matrix index problem
The problem of 1 pixel border on the mobile terminal
学会打字后的思考
I JS deep copy and shallow copy
MySQL stored procedures and functions
An error occurs when the addressable assets system project is packaged. Runtimedata is null
Communication between RING3 and ring0
Es index (document name) fuzzy query method (database name fuzzy query method)
JSX syntax rules
三十.什么是vm和vc?
Unity Odin ProgressBar add value column
LeetCode 232、用栈实现队列