fourthnf_karenmcvay
TRANSCRIPT
-
7/30/2019 FourthNF_KarenMcVay
1/25
4TH
NORMAL FORM
By: Karen McVay
-
7/30/2019 FourthNF_KarenMcVay
2/25
REVIEW OF NFs
1NF All values of the columns areatomic. That is, they contain no
repeating values.
2NF it is in 1NF and every non-key
column is fully dependent upon theprimary key.
-
7/30/2019 FourthNF_KarenMcVay
3/25
REVIEW OF NF Cont
3NF it is already in 2NF and every non-key column
is non transitively dependent upon its primary key. Inother words, all non-key attributes are functionally
dependent only upon the primary key.
BCNF A relation is in BCNF if every determinant is a
candidate key. This is an improved form of thirdnormal form.
Determinant: an attribute on which some other attributeis fully functionally dependent
-
7/30/2019 FourthNF_KarenMcVay
4/25
4th Normal Form
A Boyce Codd normal form relation is infourth normal form if
(a) there is no multi value dependency inthe relation or
(b) there are multi value dependency butthe attributes, which are multi valuedependent on a specific attribute, aredependent between themselves.
-
7/30/2019 FourthNF_KarenMcVay
5/25
4thNormal Form Cont
This is best discussed through mathematical notation.
Assume the following relation
R(a:pk1, b:pk2, c:pk3)
Recall that a relation is in BCNF if all its determinantare candidate keys, in other words eachdeterminant can be used as a primary key.
Because relation Rhas only one determinant (a, b,c), which is the composite primary key and sincethe primary is a candidate key therefore R is inBCNF.
-
7/30/2019 FourthNF_KarenMcVay
6/25
4thNormal Form Cont
Now R may or may not be in fourth normal form.
1. If R contains no multi value dependency then R will be inFourth normal form.
2. Assume R has the following two-multi value dependencies:
a --->> b and a --->> c
In this case R will be in the fourth normal form ifb and cdependent on each other.
However if b and c are independent of each other then R isnot in fourth normal form and the relation has to be
projected to following two non-loss projections. These non-loss projections will be in fourth normal form.
-
7/30/2019 FourthNF_KarenMcVay
7/25
Many-to-many relationships
Fourth Normal Form applies to situationsinvolving many-to-many relationships.
In relational databases, many-to-manyrelationships are expressed throughcross-reference tables.
4th Normal Form Cont
-
7/30/2019 FourthNF_KarenMcVay
8/25
Note about FDs and MVDs
Every Functional Dependency is a MVD
(ifA1A2An B1B2Bn , then A1A2An B1B2Bn )
FDs rule out certain tuples (i.e. ifA B thentwo tuples will not have the same value for
A and different values for B)
MVDs do not rule out tuples. Theyguarantee that certain tuples must exist.
-
7/30/2019 FourthNF_KarenMcVay
9/25
Formal Definitions
Fourth Normal Form- ifRis valid BCNF and- given the non-trivial MVD:A1A2An B1B2Bn
{A1A2An} is a superkey
A MVD:A1A2An B1B2Bn for a Relation Ris non-trivialif:1. none of the Bs are among theAs2. Not all of the attributes ofR are among theAs and Bs
A MVD is trivial if it contains all the variations ofA1A2Anx B1B2Bn.
A relation cannot be decomposed any further (under4NF rules) if it has a trivial MVD
-
7/30/2019 FourthNF_KarenMcVay
10/25
Consider a case of class enrollment. Eachstudent can be enrolled in one or more
classes and each class can contain one ormore students.
Clearly, there is a many-to-many relationshipbetween classes and students. This
relationship can be represented by aStudent/Class cross-reference table:
{StudentID, ClassID}
Example 1
-
7/30/2019 FourthNF_KarenMcVay
11/25
Example 1 Cont
The key for this table is the combination ofStudentID and ClassID. To avoid violation of2NF, all other information about each studentand each class is stored in separate Studentand Class tables, respectively.
Note that each StudentID determines not aunique ClassID, but a well-defined, finite setofvalues. This kind of behavior is referred to asmulti-valued dependency of ClassID onStudentID.
-
7/30/2019 FourthNF_KarenMcVay
12/25
Consider another example with two many-to-manyrelationships, between students and classes andbetween classes and teachers.
Example 2
Students Classes* *
Also, a many-to-many relationship betweenstudents and teachers is implied.
Classes Teachers* *
-
7/30/2019 FourthNF_KarenMcVay
13/25
However, the business rules do not constrain thisrelationship in any waythe combination of StudentIDand TeacherID does not contain any additionalinformation beyond the information implied by thestudent/class and class/teacher relationships.
Consequentially, the student/class and class/teacherrelationships are independent of each othertheserelationships have no additional constraints. Thefollowing table is, then, in violation of 4NF:
{StudentID, ClassID, TeacherID}
Example 2 Cont
-
7/30/2019 FourthNF_KarenMcVay
14/25
As an example of the anomalies that canoccur, realize that it is not possible to add a
new class taught by some teacher withoutadding at least one student who is enrolledin this class.
To achieve 4NF, represent eachindependent many-to-many relationshipthrough its own cross-reference table.
4th NF and Anomalies
-
7/30/2019 FourthNF_KarenMcVay
15/25
4th Normal Form and anomaliesCont
Case 1:
Assume the following relation:Employee (Eid:pk1, Language:pk2, Skill:pk3)
No multi value dependency,
therefore R is in fourth normalform.
-
7/30/2019 FourthNF_KarenMcVay
16/25
case 2:Assume the following relation with multi-valuedependency:
Employee (Eid:pk1, Languages:pk2, Skills:pk3)Eid --->> Languages Eid --->> Skills
Languages and Skills are dependent.This says an employee speak several languages andhas several skills. However for each skill a specificlanguage is used when that skill is practiced.
4th Normal Form and
anomalies Cont
-
7/30/2019 FourthNF_KarenMcVay
17/25
Thus employee 100 when he/she teaches
speaks English but when he cooks speaksFrench. This relation is in fourth normal formand does not suffer from any anomalies.
Eid Language Skill100 English Teaching
100 Kurdish Politic
100 French Cooking200 English Cooking
200 Arabic Singing
-
7/30/2019 FourthNF_KarenMcVay
18/25
case 3:Assume the following relation with multi-value dependency:
Employee (Eid:pk1, Languages:pk2, Skills:pk3)
Eid --->> Languages Eid --->> Skills
Languages and Skills are independent.
4th Normal Form and
anomalies Cont
-
7/30/2019 FourthNF_KarenMcVay
19/25
Eid Language Skill
100 English Teaching
100 Kurdish Politic
100 English Politic
100 Kurdish Teaching
200 Arabic Singing
4th Normal Form and
anomalies ContThis relation is not in fourth normal form and suffersfrom all three types of anomalies.
-
7/30/2019 FourthNF_KarenMcVay
20/25
Insertion anomaly: To insert row (200 English Cooking) wehave to insert two extra rows (200 Arabic cooking), and(200 English Singing) otherwise the database will be
inconsistent. Note the table will be as follow:
Eid Language Skill
100 English Teaching
100 Kurdish Politics
100 English Politics
100 Kurdish Teaching
200 Arabic Singing
200 English Cooking
200 Arabic Cooking
200 English Singing
-
7/30/2019 FourthNF_KarenMcVay
21/25
Deletion anomaly: If employee 100 discontinue politicskill we have to delete two rows:
(100 Kurdish Politic), and (100 English Politic) otherwise
the database will be inconsistent.
Eid Language Skill
100 English Teaching
100 Kurdish Politics
100 English Politics
100 Kurdish Teaching
200 Arabic Singing
200 English Cooking
200 Arabic Cooking
200 English Singing
-
7/30/2019 FourthNF_KarenMcVay
22/25
More anomalies
Update anomaly: If employee 200changes his skill from singing to
dancing we have to make changesin more than one place.
-
7/30/2019 FourthNF_KarenMcVay
23/25
The relation is projected to the following two non-lossprojections which are in forth normal form
Emplyee_Language(Eid:pk1, Languages:pk2)
Eid Language
100 English
100 Kurdish
200 Arabic
-
7/30/2019 FourthNF_KarenMcVay
24/25
Emplyee_Language(Eid:pk1, Skills:pk2)
Eid Skill
100 Teaching
100 Politic
200 Singing
Cont
-
7/30/2019 FourthNF_KarenMcVay
25/25
References
Functional Dependency (Normalization)http://www.emunix.emich.edu/~khaila
ny/files/Normalization.htm
Multivalued Dependencies (Ozmar Zaine):
http://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node13.html
http://www.emunix.emich.edu/~khailany/files/Normalization.htmhttp://www.emunix.emich.edu/~khailany/files/Normalization.htmhttp://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node13.htmlhttp://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node13.htmlhttp://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node13.htmlhttp://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node13.htmlhttp://www.emunix.emich.edu/~khailany/files/Normalization.htmhttp://www.emunix.emich.edu/~khailany/files/Normalization.htm