数据库设计(六)第二范式(2NF)?
For a table to be in the Second Normal Form, it must satisfy two conditions:
- The table should be in the First Normal Form.
- There should be no Partial Dependency(部分依赖是什么鬼).
What is Partial Dependency? Do not worry about it. First let's understand what is Dependency in a table?
What is Dependency?
Let's take an example of a Student table with columns student_id, name, reg_no(registration number), branch and address(student's home address).

Even for a case, where student names are same, if we know the student_id we can easily fetch the correct record.In this table, student_id is the primary key and will be unique for every row, hence we can use student_id to fetch any row of data from this table

I can ask from branch name of student with student_id 10, and I can get it. Similarly, if I ask for name of student with student_id 10 or 11, I will get it. So all I need is student_id and every other column depends on it, or can be fetched using it.Hence we can say a Primary Key for a table is the column or a group of columns(composite key) which can uniquely identify each record in the table.
This is Dependency and we also call it Functional Dependency.
What is Partial Dependency?
Now that we know what dependency is, we are in a better state to understand what partial dependency is.
For a simple table like Student, a single column like student_id can uniquely identfy all the records in a table.
But this is not true all the time. So now let's extend our example to see if more than 1 column together can act as a primary key.
Let's create another table for Subject, which will have subject_id and subject_name fields and subject_id will be the primary key.

Let's create another table Score, to store the marks obtained by students in the respective subjects. We will also be saving name of the teacher who teaches that subject along with marks.Now we have a Student table with student information and another table Subject for storing subject information.

Together, student_id + subject_id forms a Candidate Key(learn about Database Keys) for this table, which can be the Primary key.In the score table we are saving the student_id to know which student's marks are these and subject_id to know for which subject the marks are for.
Confused, How this combination can be a primary key?
See, if I ask you to get me marks of student with student_id 10, can you get it from this table? No, because you don't know for which subject. And if I give you subject_id, you would not know for which student. Hence we need student_id + subject_id to uniquely identify any row.
But where is Partial Dependency?
Now if you look at the Score table, we have a column names teacher which is only dependent on the subject, for Java it's Java Teacher and for C++ it's C++ Teacher & so on.
Now as we just discussed that the primary key for this table is a composition of two columns which is student_id & subject_id but the teacher's name only depends on subject, hence the subject_id, and has nothing to do with student_id.
This is Partial Dependency, where an attribute in a table depends on only a part of the primary key and not on the whole key.
How to remove Partial Dependency?
There can be many different solutions for this, but out objective is to remove teacher's name from Score table.
The simplest solution is to remove columns teacher from Score table and add it to the Subject table. Hence, the Subject table will become:

And our Score table is now in the second normal form, with no partial dependency.

Quick Recap
- For a table to be in the Second Normal form, it should be in the First Normal form and it should not have Partial Dependency.
- Partial Dependency exists, when for a composite primary key, any attribute in the table depends only on a part of the primary key and not on the complete primary key.
- To remove Partial dependency, we can divide the table, remove the attribute which is causing partial dependency, and move it to some other table where it fits in well.
数据库设计(六)第二范式(2NF)?的更多相关文章
- 转!!数据库 第一范式(1NF) 第二范式(2NF) 第三范式(3NF)的 联系和区别
范式:英文名称是 Normal Form,它是英国人 E.F.Codd(关系数据库的老祖宗)在上个世纪70年代提出关系数据库模型后总结出来的,范式是关系数据库理论的基础,也是我们在设计数据库结构过程中 ...
- [MySQL] 关系型数据库的设计范式 1NF 2NF 3NF BCNF
一.缘由: 要做好DBA,就要更好地理解数据库设计范式.数据库范式总结概览: 为了更好地理解数据库的设计范式,这里借用一下知乎刘慰老师的解释,很通俗易懂.非常感谢! 二.具体说明: 首先要明白”范 ...
- Oracle笔记(十六) 数据库设计范式
数据库设计范式是一个很重要的概念,但是这个重要程度只适合于参考.使用数据库设计范式,可以让数据表更好的进行数据的保存,因为再合理的设计,如果数据量一大也肯定会存在性能上的问题.所以在开发之中,唯一可以 ...
- 优化MySchool数据库设计之【巅峰对决】
优化MySchool数据库设计 之独孤九剑 船舶停靠在港湾是很安全的,但这不是造船的目的 By:北大青鸟五道口原玉明老师 1.学习方法: 01.找一本好书 初始阶段不适合,可以放到第二个阶段,看到知识 ...
- SQL Server 数据库设计
一.数据库设计的必要性 在实际的软件项目中,如果系统中需要存储的数据量比较大,需要设计的表比较多,表与表之间的关系比较复杂,那我们就需要进行规范的数据库设置.如果不经过数据库的设计,我们构建的数据库不 ...
- 数据库范式(1NF 2NF 3NF BCNF)
http://blog.csdn.net/xuxurui007/article/details/7738330 http://www.cnblogs.com/laodao1/archive/2009/ ...
- 七、Oracle 数据库设计
1. 原始单据与实体之间的关系 可以是一对一.一对多.多对多的关系.在一般情况下,它们是一对一的关系:即一张原始单据对应且只对应一个实体. 在特殊情况下,它们可能是一对多或多对一的关系,即一张原始单证 ...
- Mysql之数据库设计
一.三大范式 1.第一范式:消除一个字段包含多个数据库值,消除一个记录包含重复的组(单独的一列包含多个项目),即可满足1NF. 2.第二范式:消除部分依赖性即可转化为2NF.部分依赖性表示一个记录中包 ...
- DataBase 之 数据库设计六大范式
范式是符合某一种级别的关系模式的集合.关系数据库中的关系必须满足一定的要求,即满足不同的范式. 目前关系数据库有六种范式:第一范式(1NF).第二范式(2NF).第三范式(3NF).第四范式(4NF) ...
- 优化MySchool数据库设计总结
数据库的设计 一:什么是数据库设计? 数据库设计就是将数据库中的数据实体以及这些数据实体之间的关系,进行规范和结构化的过程. 二:为什么要实施数据库设计? 1:良好的数据库设计可以有效的解决数据冗 ...
随机推荐
- 移动APP安全在渗透测试中的应用
安全爱好者研究的往往是app的本地安全,比如远控.应用破解.信息窃取等等,大多人还没有关注到app服务端的安全问题,于是在这块的安全漏洞非常多. 移动app大多通过web api服务的方式跟服务端交互 ...
- MyEclipse安装后需要进行的配置
摘自: http://hi.baidu.com/timesten/item/c826983a6f9654ffde2221c0 MyEclipse安装后需要进行的配置 在MyEclipse中编写Web ...
- 猜想:一组勾股数a^2+b^2=c^2中,a,b之一必为4的倍数。
证明: 勾股数可以写成如下形式 a=m2-n2 b=2mn c=m2+n2 而m,n按奇偶分又以下四种情况 m n 奇 偶 ① 偶 奇 ② 偶 偶 ③ 奇 奇 ④ 上面①②③三种情况中,mn中存在至少 ...
- java将SSL证书导入系统密钥库
之前安装JIRA和Confluence,配置了SSL证书之后遇到应用程序链接的问题: SSL证书不被信任,导致JIRA和Confluence无法关联. 尝试过很多办法无果之后打算放弃. 最终还是放弃了 ...
- C#字符串来袭——因为爱,所以爱
一直以来都喜欢谢霆锋,喜欢他身上的那股劲,也一直喜欢唱他的歌,比如这首最广为人知的<因为爱,所以爱>:因为爱所以爱,温柔经不起安排,愉快那么快,不要等到互相伤害...是的,没到互相伤害,他 ...
- JMeter 五:监控服务器
参考:http://jmeter.apache.org/usermanual/build-monitor-test-plan.html 添加Thread Group 添加方法:Test Plan上右键 ...
- 我装win8与win7双系统的血泪史
前段时间教徒弟装系统,由于笔记本原带了win8,他不想换掉原来的系统.遂决定装个双系统.于是按照之前的一贯套路,但是出现了问题. 一. 首先遇到的问题是:如何进入BIOS,设置成U盘启动.Win XP ...
- Java创建和读取Json
在Java中构造和解析JSON我用的是org.json,附件为相应的org.json.jar. 下面是两个函数,一个是创建JSON,一个是从文本构造JSON并解析之. 创建json: //constr ...
- 怎样将游戏从Unity导到iOS设备上
当我开始开发自己的iOS游戏时,我会考虑的第一件事便是如何将其导出到设备中,如此有效地测试我的游戏.最初,该过程看似很长且复杂,我所遇到的主要问题是,尽管存在许多资源,但是它们并非完全来自同样的地方, ...
- 算法笔记_079:蓝桥杯练习 区间k大数查询(Java)
目录 1 问题描述 2 解决方案 1 问题描述 问题描述 给定一个序列,每次询问序列中第l个数到第r个数中第K大的数是哪个. 输入格式 第一行包含一个数n,表示序列长度. 第二行包含n个正整数,表 ...