nf范式_第三范式(3NF)

nf范式

Third Normal Form is an upgrade to Second Normal Form. When a table is in the Second Normal Form and has no transitive dependency, then it is in the Third Normal Form.

第三范式是对第二范式的升级。 当表为第二范式且没有传递依存关系时,则为第三范式。

The video below covers the concept of Third Normal Form in details.

下面的视频详细介绍了第三范式的概念。

演示地址

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

在上一个教程中,我们了解了第二种范式 ,甚至将Score表标准化为第二种范式。

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

因此,让我们使用同一示例,其中有3个表StudentSubjectScore

学生桌 (Student Table)
student_idnamereg_nobranchaddress
10Akon07-WYCSEKerala
11Akon08-WYITGujarat
12Bkon09-WYITRajasthan
学生卡 名称 reg_no 地址
10 阿Kong 07年 自学考试 喀拉拉邦
11 阿Kong 08年 古吉拉特邦
12 布Kong 09月 拉贾斯坦邦
主题表 (Subject Table)
subject_idsubject_nameteacher
1JavaJava Teacher
2C++C++ Teacher
3PhpPhp Teacher
subject_id subject_name 老师
1个 Java Java老师
2 C ++ C ++老师
3 p Php老师
得分表 (Score Table)
score_idstudent_idsubject_idmarks
110170
210275
311180
score_id 学生卡 subject_id 分数
1个 10 1个 70
2 10 2 75
3 11 1个 80

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.

在“分数”表中,我们需要存储更多信息,即考试名称和总分,因此让我们在“分数”表中再添加两列。

score_idstudent_idsubject_idmarksexam_nametotal_marks
score_id 学生卡 subject_id 分数 考试名称 total_marks

第三范式的要求 (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.

exam_nametotal_marks添加到我们的分数表后,它现在可以保存更多数据。 我们的Score表的主键是一个复合键,这意味着它由两个属性或列→ 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.

我们新的列exam_name取决于学生和学科。 例如,机械工程专业的学生将参加Workshop考试,而计算机科学专业的学生则没有。 对于某些科目,您需要进行Practical考试,而对于某些科目则没有。 因此,我们可以说exam_name依赖于student_idsubject_id

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

那第二个新列total_marks呢? 它是否取决于我们的分数表的主键?

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.

好吧, total_marks列取决于exam_name因为总分的变化与考试类型有关。 例如,实践的得分较低,而理论考试的得分较高。

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.

但是, exam_name只是分数表中的另一列。 它不是主键,也不是主键的一部分, total_marks依赖total_marks

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.

同样,解决方案非常简单。 从“分数”表中取出“ exam_name和“ total_marks ”列,并将其放入“ 考试”表中,并在需要时使用exam_id

得分表:第3范式 (Score Table: In 3rd Normal Form)
score_idstudent_idsubject_idmarksexam_id
score_id 学生卡 subject_id 分数 考试编号
新的考试表 (The new Exam table)
exam_idexam_nametotal_marks
1Workshop200
2Mains70
3Practicals30
考试编号 考试名称 total_marks
1个 作坊 200
2 电源 70
3 实用性 30

消除传递依赖性的优势 (Advantage of removing Transitive Dependency)

The advantage of removing transitive dependency is,

消除传递依赖的优点是

  • Amount of data duplication is reduced.

    减少了数据重复量。

  • Data integrity achieved.

    实现数据完整性。

翻译自: https://www.studytonight.com/dbms/third-normal-form.php

nf范式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值