当前位置:网站首页>数据库中的范式:第一范式,第二范式,第三范式
数据库中的范式:第一范式,第二范式,第三范式
2022-07-05 10:17:00 【小的时候可菜了】
元组:表中的一行
码:表中的一列
候选码:可唯一标识,如通过(身份证号码)或者 (学校,班级,学号)可唯一标识一个人;主属性:候选码中出现过的属性
主码 : 也叫主键,从候选码中选出一个老大
外码也叫外键。如果一个关系中的一个属性是另外一个关系中的主码则这个属性为外码
第一范式,第二范式,第三范式的超简单介绍
第一范式: 不可再分
如一个表中有两个属性:
公司、商品(名称、数量),但商品可由名称、数量表示,不符合,而公司、名称、数量符合
第二范式:建立在第一范式基础上,消除部分依赖
| 订单号 | 产品号 | 产品数量 | 产品折扣 | 产品价格 | 订单金额 | 订单时间 |
|---|---|---|---|---|---|---|
| 10001 | 25 | 100 | 0.9 | 9 | 5000 | 2022-07-22 |
| 10001 | 26 | 200 | 0.8 | 9 | 7000 | 2022-07-23 |
订 单 号 、 产 品 号 → 产 品 数 量 、 产 品 折 扣 、 产 品 价 格 订 单 号 → 订 单 金 额 、 订 单 时 间 订单号、产品号\to产品数量、产品折扣、产品价格 \\ 订单号\to 订单金额、订单时间 订单号、产品号→产品数量、产品折扣、产品价格订单号→订单金额、订单时间
‘订单号’ 和 ‘产品号’ 是表的主键(主码),这两个字段一起决定了 ‘产品数量‘ ’产品折扣‘ ’产品价格‘ ,
而‘订单金额’和‘订单时间’仅由‘订单号’决定,不是由 主键(‘订单号’ 和 ‘产品号’)共同决定,所以‘订单金额’和‘订单时间’是部分依赖于主键
正确版本
| 订单号 | 产品号 | 产品数量 | 产品折扣 | 产品价格 |
|---|---|---|---|---|
| 10001 | 25 | 100 | 0.9 | 9 |
| 10001 | 26 | 200 | 0.8 | 9 |
| 订单号 | 订单金额 | 订单时间 |
|---|---|---|
| 10001 | 5000 | 2022-07-22 |
| 10001 | 7000 | 2022-07-23 |
第三范式:建立在第二范式基础上,消除传递依赖
| 身份证号 | 姓名 | 性别 | 年龄 |
|---|---|---|---|
| 34666666666 | 张三 | 男 | 22 |
身 份 证 → 姓 名 → 性 别 、 年 龄 身份证 \to 姓名 \to 性别、年龄 身份证→姓名→性别、年龄
“性别”和“年龄”虽然间接依赖‘身份证号’,但直接依赖的是“姓名”,正确版本
| 身份证号 | 姓名 |
|---|---|
| 34666666666 | 张三 |
| 姓名 | 性别 | 年龄 |
|---|---|---|
| 张三 | 男 | 22 |
传递函数依赖: 身 份 证 → 姓 名 → 性 别 、 年 龄 但 是 性 别 、 年 龄 ↛ 姓 名 ↛ 身 份 证 身份证 \to 姓名 \to 性别、年龄 ~~~~~~但是~~~~~~ 性别、年龄 \not\to 姓名 \not\to 身份证 身份证→姓名→性别、年龄 但是 性别、年龄→姓名→身份证
边栏推荐
- leetcode:1200. 最小绝对差
- Singleton mode encapsulates activity management class
- Go项目实战—参数绑定,类型转换
- 最全是一次I2C总结
- C语言实现QQ聊天室小项目 [完整源码]
- Window下线程与线程同步总结
- 橫向滾動的RecycleView一屏顯示五個半,低於五個平均分布
- [论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems
- Events and bubbles in the applet of "wechat applet - Basics"
- 《通信软件开发与应用》课程结业报告
猜你喜欢

SAP UI5 ObjectPageLayout 控件使用方法分享

Universal double button or single button pop-up

Advanced opencv:bgr pixel intensity map

非技術部門,如何參與 DevOps?
![[observation] with the rise of the](/img/9a/8bbf98e6aed80638f4340aacec2ea9.jpg)
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?

mongoDB副本集

Learning II of workmanager

> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair

How can non-technical departments participate in Devops?

SAP ui5 objectpagelayout control usage sharing
随机推荐
Swift saves an array of class objects with userdefaults and nssecurecoding
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
微信小程序触底加载与下拉刷新的实现
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
QT VT100 parser
How to plan the career of a programmer?
AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」
《剑来》语句摘录(七)
Usage differences between isempty and isblank
In wechat applet, after jumping from one page to another, I found that the page scrolled synchronously after returning
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
Solution of ellipsis when pytorch outputs tensor (output tensor completely)
How did automated specification inspection software develop?
伪类元素--before和after
一个可以兼容各种数据库事务的使用范例
《通信软件开发与应用》课程结业报告
ConstraintLayout官方提供圆角ImageFilterView
[论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
isEmpty 和 isBlank 的用法区别
Using directive in angualr2 to realize that the picture size changes with the window size