当前位置:网站首页>数据库设计三大范式
数据库设计三大范式
2022-07-26 18:38:00 【知其黑、受其白】
阐述
目前关系数据库有六种范式:
第一范式(1NF)、
第二范式(2NF)、
第三范式(3NF)、
巴斯-科德范式(BCNF)、
第四范式(4NF)、
第五范式(5NF,又称完美范式)。
而通常我们用的最多的就是:第一范式(1NF)、第二范式(2NF)、第三范式(3NF)。
也就是本文要讲的“三大范式”。
第一范式(1NF)
要求数据库表的每一列都是不可分割的原子数据项。
举例说明:

在上面的表中,“家庭信息” 和 “学校信息” 列均不满足原子性的要求,故不满足第一范式,调整如下:

可见,调整后的每一列都是不可再分的,因此满足第一范式(1NF);
第二范式(2NF)
在1NF的基础上,非码属性必须完全依赖于候选码(在1NF基础上消除非主属性对主码的部分函数依赖)
第二范式需要确保数据库表中的每一列都和主键相关,而不能只与主键的某一部分相关(主要针对联合主键而言)。
举例说明:

在上图所示的情况中,同一个订单中可能包含不同的产品,因此主键必须是 “订单号” 和 “产品号” 联合组成,
但可以发现,产品数量、产品折扣、产品价格与 “订单号” 和 “产品号” 都相关,但是订单金额和订单时间仅与 “订单号” 相关,与 “产品号” 无关,
这样就不满足第二范式的要求,调整如下,需分成两个表:

第三范式(3NF)
在2NF基础上,任何非主属性不依赖于其它非主属性(在2NF基础上消除传递依赖)
第三范式需要确保数据表中的每一列数据都和主键直接相关,而不能间接相关。
举例说明:

上表中,所有属性都完全依赖于学号,所以满足第二范式,但是 “班主任性别” 和 “班主任年龄” 直接依赖的是 “班主任姓名”,而不是主键 “学号”,所以需做如下调整:

这样以来,就满足了第三范式的要求。
ps:如果把上表中的班主任姓名改成班主任教工号可能更确切,更符合实际情况,不过只要能理解就行。
总结
第一范式的关键词是列的原子性
第二范式的关键词是不能包含部分依赖
第三范式的关键词是不能包含传递依赖。
边栏推荐
- 周末看点回顾|数字人民币产业联盟成立;中国移动宣布:和飞信将停止服务…
- Pycharm加载conda创建pytorch虚拟环境报错,在conda命令行正常
- Cannot find current proxy: Set ‘exposeProxy‘ property on Advised to ‘true‘ to make it available
- 原 iOS面试题收集
- eadiness probe failed: calico/node is not ready: BIRD is not ready: Error querying BIRD: unable to c
- 【YOLOv5】--详细版训练自己的数据集 保姆级学习日志记录 手把手教程
- 软件测试——自动化测试框架有哪些?
- 中信建投启牛学堂开户是安全的吗,启牛是干嘛的
- To add a composite primary key
- Redis介绍
猜你喜欢

C # upper computer development - modify the window icon and exe file Icon

工作13年后,个人的一点软件测试经历及感想……

2022/07/26 学习笔记 (day16) 抽象与接口

"Weilai Cup" 2022 Niuke summer multi school training camp 1
![[yolov5] - detailed version of training your own dataset, nanny level learning, logging, hand-in-hand tutorial](/img/34/5ab529ff6d8d0fd3827c440299964d.png)
[yolov5] - detailed version of training your own dataset, nanny level learning, logging, hand-in-hand tutorial

Customer cases | focus on process experience to help bank enterprise app iteration

服务发现原理分析与源码解读

服务器内存故障预测居然可以这样做

Machine learning notes - building a recommendation system (6) six automatic encoders for collaborative filtering

Leetcode-138-copy linked list with random pointer
随机推荐
Fair lock process of reentrantlock learning
Selenium+Web自动化框架的Case
Customer cases | focus on process experience to help bank enterprise app iteration
Advantages of advanced anti DDoS IP in Hong Kong and which industries are suitable for use
Pychart loads CONDA to create a pytorch virtual environment and reports an error. It is normal on the CONDA command line
How to write the test case of mobile app? What are the mobile app test points?
C#中关闭窗体的四种方法
C # create and read dat file cases
UIAutomator2常用类之UiObject2
PyQt5快速开发与实战 3.6 打包资源文件
CIO guide to business change
conda转移项目虚拟环境必备技能+pip速度下载太慢解决办法
DDL,DQL,DML语句
YOLO V2详解
Spatiotemporal prediction 4-graph WaveNet
Test interview question set UI automated test
工作13年后,个人的一点软件测试经历及感想……
Sre person in charge of station B personally describes the multi activity disaster recovery construction after the 713 accident | takintalks share
“蔚来杯“2022牛客暑期多校训练营1
Talk about how to use redis to realize distributed locks?