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

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

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

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

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

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

这样以来,就满足了第三范式的要求。
ps:如果把上表中的班主任姓名改成班主任教工号可能更确切,更符合实际情况,不过只要能理解就行。
总结
第一范式的关键词是列的原子性
第二范式的关键词是不能包含部分依赖
第三范式的关键词是不能包含传递依赖。
边栏推荐
- Design of intelligent weighing system based on Huawei cloud IOT (STM32) [II] there is information at the end
- Talk about how to use redis to realize distributed locks?
- Image preview embedding location of blog maintenance record
- Thinking personally
- The difference between advanced anti DDoS server and advanced anti DDoS IP
- Onion group joined hands with oceanbase to realize distributed upgrading, and global data has achieved cross cloud integration for the first time
- 配置服务器环境
- Several ways to view containers
- 基于华为云 IOT 设计智能称重系统 (STM32)【二】结尾有资料
- 【YOLOv5】--详细版训练自己的数据集 保姆级学习日志记录 手把手教程
猜你喜欢

基于ABP实现DDD--领域逻辑和应用逻辑

Ijcai2022 meeting! Brescia et al. Tutorial of evidential reasoning and learning, describing its latest progress, with 96 slides attached

知识管理系统是什么?你需要知道这些

To add a composite primary key

基于华为云 IOT 设计智能称重系统 (STM32)【二】结尾有资料

LeetCode每日一练 —— 189. 轮转数组

C # get local time / system time

基于华为云 IOT 设计智能称重系统 (STM32)【一】

2022/07/26 学习笔记 (day16) 链表和栈

测试人员必须知道的软件流程
随机推荐
Save gas chitoken usage
Image preview embedding location of blog maintenance record
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_ scale_ factor‘
Design of intelligent weighing system based on Huawei cloud IOT (STM32) [II] there is information at the end
论文精读:YOLOV2——YOLO9000:Better, Faster, Stronger
How to write the test case of mobile app? What are the mobile app test points?
视频直播源码,实现上下滚动的广告效果
Without Lin benjian, there would be no TSMC today!
CIO guide to business change
还在用Xshell?你out了,推荐一个更现代的终端连接工具
Sre person in charge of station B personally describes the multi activity disaster recovery construction after the 713 accident | takintalks share
Four methods of closing forms in C #
“蔚来杯“2022牛客暑期多校训练营1
openstack 虚拟机网卡被重名为cirename0
关于接口测试你想知道的都在这儿了
Chapter 9 practical modeling technology
Leetcode daily practice - 88. Merge two ordered arrays
To add a composite primary key
cuda11.2对应pytorch安装
What do indicators and labels do