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. http://my.oschina.net/China2012/blog/178655

    http://my.oschina.net/China2012/blog/178655 http://git.oschina.net/huangyong/smart-framework

  2. pyspider介绍及安装

    一.pyspider简介 1.通过python脚本进行结构化信息的提取,follow链接调度抓取控制,实现最大的灵活性 2.通过web化的脚本编写.调试环境.web展现调度状态 3.抓取环模型成熟稳定 ...

  3. ExpandListView onChildClickListener 失效

    http://stackoverflow.com/questions/11529472/expandablelistview-onchildclicklistener-not-work 首先声明:   ...

  4. Azkaban配置

    1,新建azkaban目录,用于安置azkaban程序 2,azkaban web服务器安装  解压 azkaban-web-server-2.5.0.tar.gz tar -zvxf azkaban ...

  5. next 前缀字符串

    我们在一个母字符串中查找一个子字符串有很多方法.KMP是一种最常见的改进算法,它可以在匹配过程中失配的情况下,有效地多往后面跳几个字符,加快匹配速度. 当然我们可以看到这个算法针对的是子串有对称属性, ...

  6. 通过NAT实例实现外部访问AWS的ElastiCache资源

    ElastiCache作为AWS的内存缓存组建可以说做的一点也不友好了, 你可以通过ElastiCache创建redis,memcache的实例,却不能被外部访问. 背景 人傻钱多的客户总有人傻钱多的 ...

  7. 【转】C语言中不同的结构体类型的指针间的强制转换详解

    C语言中不同类型的结构体的指针间可以强制转换,很自由,也很危险.只要理解了其内部机制,你会发现C是非常灵活的. 一. 结构体声明如何内存的分布, 结构体指针声明结构体的首地址, 结构体成员声明该成员在 ...

  8. Js、JQuery脚本兼容

    1.获取属性值 IE:$("#xxx").prop("title"); chrome:$("#xxx").attr("title& ...

  9. JMeter 六:Listener

    参考:http://jmeter.apache.org/usermanual/listeners.html Listener是用来展示Sampler结果的元件. 结果可以被展示在树.表格.图表或者简单 ...

  10. Bitmap和Drawable的互相转换

    刚好之前的项目实用到.怕遗忘了.就先记录下来.然后会用到的时候直接来这copy使用就好了. 1.Bitmap ---->Drawable: public static Drawable bitm ...