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. mysql 5.7之后版本datatime 不允许设置 0000-00-00 00:00:00 的问题

    打开mysql.ini配置文件  在mysqld下 加入sql-model验证规则即可 sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FO ...

  2. 【实践】js封装 jq siblings 方法

    思路: 1.获取调用元素的父元素下的所有子元素(即它的所有同辈元素和调用元素本身) 2.遍历调用元素父元素下的所有子元素 除调用元素外的所有元素保存在一个数组里面 代码如下: <!DOCTYPE ...

  3. 【java】Could not find or load main class

    https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean A comm ...

  4. PHP多文件上传代码练习

    HTML表单: <html> <head><title>upload file</title> <meta http-equiv="Co ...

  5. 《大话操作系统——做坚实的project实践派》(5)

    有人说我不是仅仅会玩X86吗?我如今铁板钉钉的申明:我事实上兼通:ARM.IA-32.IA-32e.AMD64. ​了解MIPS.但没做过MIPS由于确实没有对应的MIPS硬件平台. ​

  6. Java程序的结构

    1.由一个或多个独立的类组成: 2.最多一个公有类 3.源代码文件名必须与类名相同 4.类由一个或多个方法组成,其中公有类中的main()方法作为程序的入口. 注:javaSE中一定有main方法. ...

  7. 【大盛】全网首发HTC One/M7 最新本地化TrickDroid9.0/固件升级/永久root/高级,快速设置/稳定,流畅经典ROM

    了解更多请关注:点击打开链接 ROM版本 HTC One/M7_TrickDroid9.0.0 ROM作者 雪狼团队-大盛   http://weibo.com/DaShengdd Android版本 ...

  8. 【BIEE】服务启动失败,查看错误日志

    Weblogic服务日志文件:------------------------------BI Managed Server:OBIEE_HOME\user_projects\domains\bifo ...

  9. Sybase数据库应用系统调优的五大领域

    Sybase数据库应用系统调优的五大领域 2011/3/14/13:49来源:慧聪it网 本 文以“某大型商业银行的网上银行系统”这一很具有典型意义的企业级大型Sybase数据库应用系统为例,涉及了数 ...

  10. JavaScript入门:002—JS代码放置的位置

    JavaScript在页面中使用,那么这些JS代码应该放在什么位置呢?以下来看一下. 一般来说有两种方式.写在界面上和使用.js文件.1.1界面上的Head部分能够直接放在head标签内,例如以下代码 ...