For a table to be in the Second Normal Form, it must satisfy two conditions:

  1. The table should be in the First Normal Form.
  2. 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_idnamereg_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

  1. 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.
  2. 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.
  3. 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)?的更多相关文章

  1. 转!!数据库 第一范式(1NF) 第二范式(2NF) 第三范式(3NF)的 联系和区别

    范式:英文名称是 Normal Form,它是英国人 E.F.Codd(关系数据库的老祖宗)在上个世纪70年代提出关系数据库模型后总结出来的,范式是关系数据库理论的基础,也是我们在设计数据库结构过程中 ...

  2. [MySQL] 关系型数据库的设计范式 1NF 2NF 3NF BCNF

    一.缘由: 要做好DBA,就要更好地理解数据库设计范式.数据库范式总结概览: 为了更好地理解数据库的设计范式,这里借用一下知乎刘慰老师的解释,很通俗易懂.非常感谢!   二.具体说明: 首先要明白”范 ...

  3. Oracle笔记(十六) 数据库设计范式

    数据库设计范式是一个很重要的概念,但是这个重要程度只适合于参考.使用数据库设计范式,可以让数据表更好的进行数据的保存,因为再合理的设计,如果数据量一大也肯定会存在性能上的问题.所以在开发之中,唯一可以 ...

  4. 优化MySchool数据库设计之【巅峰对决】

    优化MySchool数据库设计 之独孤九剑 船舶停靠在港湾是很安全的,但这不是造船的目的 By:北大青鸟五道口原玉明老师 1.学习方法: 01.找一本好书 初始阶段不适合,可以放到第二个阶段,看到知识 ...

  5. SQL Server 数据库设计

    一.数据库设计的必要性 在实际的软件项目中,如果系统中需要存储的数据量比较大,需要设计的表比较多,表与表之间的关系比较复杂,那我们就需要进行规范的数据库设置.如果不经过数据库的设计,我们构建的数据库不 ...

  6. 数据库范式(1NF 2NF 3NF BCNF)

    http://blog.csdn.net/xuxurui007/article/details/7738330 http://www.cnblogs.com/laodao1/archive/2009/ ...

  7. 七、Oracle 数据库设计

    1. 原始单据与实体之间的关系 可以是一对一.一对多.多对多的关系.在一般情况下,它们是一对一的关系:即一张原始单据对应且只对应一个实体. 在特殊情况下,它们可能是一对多或多对一的关系,即一张原始单证 ...

  8. Mysql之数据库设计

    一.三大范式 1.第一范式:消除一个字段包含多个数据库值,消除一个记录包含重复的组(单独的一列包含多个项目),即可满足1NF. 2.第二范式:消除部分依赖性即可转化为2NF.部分依赖性表示一个记录中包 ...

  9. DataBase 之 数据库设计六大范式

    范式是符合某一种级别的关系模式的集合.关系数据库中的关系必须满足一定的要求,即满足不同的范式. 目前关系数据库有六种范式:第一范式(1NF).第二范式(2NF).第三范式(3NF).第四范式(4NF) ...

  10. 优化MySchool数据库设计总结

    数据库的设计   一:什么是数据库设计? 数据库设计就是将数据库中的数据实体以及这些数据实体之间的关系,进行规范和结构化的过程. 二:为什么要实施数据库设计? 1:良好的数据库设计可以有效的解决数据冗 ...

随机推荐

  1. unity 拿shadowmap/ sample shadow map/拿_ShadowMapTexture

    https://gamedev.stackexchange.com/questions/96051/unity-5-how-to-get-a-shadowmap UNITY_DECLARE_SHADO ...

  2. 使用JEECG过程中的问题汇总(持续更新)

    1.首次启动Tomcat服务时,控制台信息提示请使用SQL Server 2005或更高版本. <dependency> <groupId>org.jeecgframework ...

  3. Android之通知使用权

    通知使用权打开方式 设置--提示音和通知--通知使用权. 具体界面如图: 存在须要拥有通知使用权应用时: 不存在须要拥有通知使用权应用时: 用户为应用勾选复选框后系统弹dialog须要用户进一步确认时 ...

  4. weblogic基本安装部署

    1.3.1 安装WebLogic10(1) <JavaEE程序设计与应用开发>第1章JavaEE介绍和环境配置,本章首先介绍了JavaEE的基本理论,然后对本书将要使用的软件:JDK.服务 ...

  5. web页面内容优化管理与性能技巧

    来源:GBin1.com 回 想一下,以前我们不得不花费大量时间去优化页面内容(图片.CSS等等),如今用户有更快速的互联网链接,我们似乎能够使用更大的图像或更大的闪 存文件,里面包含的有视频或者图片 ...

  6. 移动端(阿里rem)布局

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Unity3D实现3D立体游戏原理及过程,需偏振眼镜3D显

    http://tieba.baidu.com/p/3038509618?fr=ala0&pstaala=3

  8. 算法笔记_069:Floyd算法简单介绍(Java)

    目录 1 问题描述 2 解决方案 2.1 使用Floyd算法得到最短距离示例 2.2 具体编码   1 问题描述 何为Floyd算法? Floyd算法功能:给定一个加权连通图,求取从每一个顶点到其它所 ...

  9. Nutch的发展历程(转)

    2002年8月由Doug Cutting发起,托管于Sourceforge,之后发布了0.4.0.5.0.6三个版本 2004年9月Oregon State University(俄勒冈州立大学)采用 ...

  10. 采用QHD分辨率使用kinect2_calibration,完成QHD图像校正

    //.................................................................................//采用QHD分辨率使用kinec ...