zoukankan      html  css  js  c++  java
  • 数据库设计(七)第三范式(3NF)

    In our last tutorial, we learned about the second normal form and even normalized our Score table into the 2nd Normal Form.

    So let's use the same example, where we have 3 tables, StudentSubject and Score.

    Student Table

    Subject Table

    Score Table

    In the Score table, we need to store some more information, which is the exam name and total marks, so let's add 2 more columns to the Score table.

    Requirements for Third Normal Form



    For a table to be in the third normal form,

    1. It should be in the Second Normal form.
    2. And it should not have Transitive Dependency.

    What is Transitive Dependency?

    With exam_name and total_marks added to our Score table, it saves more data now. Primary key for our Score table is a composite key, which means it's made up of two attributes or columns → student_id + subject_id.

    Our new column exam_name depends on both student and subject. For example, a mechanical engineering student will have Workshop exam but a computer science student won't. And for some subjects you have Prctical exams and for some you don't. So we can say that exam_name is dependent on both student_id and subject_id.

    And what about our second new column total_marks? Does it depend on our Score table's primary key?

    Well, the column total_marks depends on exam_name as with exam type the total score changes. For example, practicals are of less marks while theory exams are of more marks.

    But, exam_name is just another column in the score table. It is not a primary key or even a part of the primary key, and total_marks depends on it.

    This is Transitive Dependency. When a non-prime attribute depends on other non-prime attributes rather than depending upon the prime attributes or primary key.


    How to remove Transitive Dependency?

    Again the solution is very simple. Take out the columns exam_name and total_marks from Score table and put them in an Exam table and use the exam_id wherever required.

    Score Table: In 3rd Normal Form

    The new Exam table


    Advantage of removing Transtive Dependency



    The advantage of removing transtive dependency is,

    • Amount of data duplication is reduced.
    • Data integrity achieved.
  • 相关阅读:
    linux下光标定位和清屏函数
    使用NHibernate的时候出现“指定的转换无效”的错误
    UI 界面:技术决定一切
    BeamTarget红外线的末尾
    Chicken的代码解剖:6 PlayerController
    kismet模块创建
    Projectile重构
    关卡设计师优化关卡
    一些主类的继承关系
    EA iOS平台《质量效应》《死亡空间》的界面
  • 原文地址:https://www.cnblogs.com/tuhooo/p/8461611.html
Copyright © 2011-2022 走看看