A Simplified COMPANY Relational Database Schema: Slide 10-1
A Simplified COMPANY Relational Database Schema: Slide 10-1
schema
Slide 10- 1
Figure 10.3 Two relation schemas suffering from
update anomalies
Slide 10- 2
May 2012 91.2814 3
• Information is stored redundantly
– Wastes storage
– Causes problems with update anomalies
• Insertion anomalies
• Deletion anomalies
• Modification anomalies
• Normal form:
– Condition using keys and FDs of a relation to
certify whether a relation schema is in a particular
normal form
Slide 10- 5
Normalization
91.2914 6
Normalization
There is a sequence to normal forms:
1NF is considered the weakest,
2NF is stronger than 1NF,
3NF is stronger than 2NF, and
Also,
any relation in 3NF is in 2NF; and
any relation in 2NF is in 1NF.
91.2914 7
Normalization
91.2914 8
Functional Dependencies (2)
• X -> Y holds if whenever two tuples have the same value for X,
they must have the same value for Y
Slide 10- 9
Examples of FD constraints (1)
• Social security number determines employee
name
– SSN -> ENAME
• Project number determines project name and
location
– PNUMBER -> {PNAME, PLOCATION}
• Employee ssn and project number determines
the hours per week that the employee works on
the project
– {SSN, PNUMBER} -> HOURS
Slide 10- 10
Functional Dependencies
91.2914 11
Functional Dependencies
EmpNum EmpEmail EmpFname EmpLname
123 [email protected] John Doe
456 [email protected] Peter Smith
555 [email protected] Alan Lee
633 [email protected] Peter Doe
787 [email protected] Alan Lee
91.2914 12
Functional Dependencies
EmpNum EmpEmail
EmpNum EmpFname 3 different ways
EmpNum EmpLname you might see FDs
depicted
EmpEmail
EmpNum EmpFname
EmpLname
91.2914 13
2.2 Inference Rules for FDs (1)
Chapter 10-14
Inference Rules for FDs (2)
Chapter 10-15
Chapter 10-16
May 2012 91.2814 17
May 2012 91.2814 18
May 2012 91.2814 19
3.2 First Normal Form
• Disallows
– composite attributes
– multivalued attributes
– nested relations; attributes whose values for an
individual tuple are non-atomic
Slide 10- 20
Figure 10.8 Normalization into 1NF
Slide 10- 21
Figure 10.9 Normalization nested relations into
1NF
Slide 10- 22
3.3 Second Normal Form (1)
• Uses the concepts of FDs, primary key
• Definitions
– Prime attribute: An attribute that is member of the primary key
K
– Full functional dependency: a FD Y -> Z where removal of any
attribute from Y means the FD does not hold any more
• Examples:
– {SSN, PNUMBER} -> HOURS is a full FD since neither SSN ->
HOURS nor PNUMBER -> HOURS hold
– {SSN, PNUMBER} -> ENAME is not a full FD (it is called a partial
dependency ) since SSN -> ENAME also holds
Slide 10- 23
Second Normal Form (2)
• A relation schema R is in second normal form
(2NF) if every non-prime attribute A in R is
fully functionally dependent on the primary
key
Slide 10- 24
Figure 10.10 Normalizing into 2NF and 3NF
Slide 10- 25
Normalization into 2NF and 3NF
Slide 10- 26
3.4 Third Normal Form (1)
• Definition:
– Transitive functional dependency: a FD X -> Z that
can be derived from two FDs X -> Y and Y -> Z
• Examples:
– SSN -> DMGRSSN is a transitive FD
• Since SSN -> DNUMBER and DNUMBER -> DMGRSSN hold
– SSN -> ENAME is non-transitive
• Since there is no set of attributes X where SSN -> X and X
-> ENAME
Slide 10- 27
Third Normal Form (2)
• A relation schema R is in third normal form (3NF) if it is in
2NF and no non-prime attribute A in R is transitively
dependent on the primary key
• R can be decomposed into 3NF relations via the process of
3NF normalization
• NOTE:
– In X -> Y and Y -> Z, with X as the primary key, we consider this a
problem only if Y is not a candidate key.
– When Y is a candidate key, there is no problem with the
transitive dependency .
– E.g., Consider EMP (SSN, Emp#, Salary ).
• Here, SSN -> Emp# -> Salary and Emp# is a candidate key.
Slide 10- 28
General Normal Form Definitions (2)
Definition:
• Superkey of relation schema R - a set of attributes S
of R that contains a key of R
Chapter 10-29
5 BCNF (Boyce-Codd Normal Form)
Chapter 10-30
Figure 10.12 Boyce-Codd normal form
91.2914 33
Transitive dependency
EmpNum DeptNum
DeptNum DeptName
91.2914 34
Partial dependency
A partial dependency exists when an attribute B is
functionally dependent on an attribute A, and A is a
component of a multipart candidate key.
FD2: InvNum InvDate
91.2914 36
First Normal Form
The following in not in 1NF
91.2914 37
First Normal Form
EmpNum EmpPhone EmpDegrees
123 233-9876
333 233-1231 BA, BSc, PhD
679 233-1231 BSc, MSc
91.2914 38
First Normal Form
EmployeeDegree
Employee
EmpNum EmpDegree
EmpNum EmpPhone
333 BA
123 233-9876
333 BSc
333 233-1231
333 PhD
679 233-1231
679 BSc
679 MSc
91.2914 39
Second Normal Form
Second Normal Form
A relation is in 2NF if it is in 1NF, and every non-key
attribute is fully dependent on each candidate key. (That is, we
don’t have any partial functional dependency.)
91.2914 40
Second Normal Form
Consider this InvLine table (in 1NF):
InvNum LineNum ProdNum Qty InvDate
InvNum, LineNum ProdNum, Qty
There are two
candidate keys.
Qty is the only non-
key attribute, and it is
InvNum InvDate
dependent on InvNum
91.2914 41
Second Normal Form
InvLine
InvNum LineNum ProdNum Qty InvDate
The above relation has redundancies: the invoice date is
repeated on each invoice line.
We can improve the database by decomposing the relation
into two relations:
InvNum LineNum ProdNum Qty
InvNum InvDate
91.2914 43
2NF, but not in 3NF, nor in BCNF:
EmployeeDept
ename ssn bdate address dnumber dname
dnumber dname.
91.2914 44
Third Normal Form
Third Normal Form
• A relation is in 3NF if the relation is in 1NF and all
determinants of non-key attributes are candidate keys
That is, for any functional dependency: X Y, where Y is
a non-key attribute (or a set of non-key attributes), X is a
candidate key.
• This definition of 3NF differs from BCNF only in the
specification of non-key attributes - 3NF is weaker than
BCNF. (BCNF requires all determinants to be candidate
keys.)
• A relation in 3NF will not have any transitive dependencies
of non-key attribute on a candidate key through another
non-key attribute.
91.2914 45
5. Multivalued Dependencies and
Fourth Normal Form (1)
Definition:
• A multivalued dependency (MVD) X —>> Y specified on relation schema
R, where X and Y are both subsets of R, specifies the following constraint
on any relation state r of R: If two tuples t1 and t2 exist in r such that t1[X]
= t2[X], then two tuples t3 and t4 should also exist in r with the following
properties, where we use Z to denote (R 2 (X υ Y)):
– t3[X] = t4[X] = t1[X] = t2[X].
– t3[Y] = t1[Y] and t4[Y] = t2[Y].
– t3[Z] = t2[Z] and t4[Z] = t1[Z].
• An MVD X —>> Y in R is called a trivial MVD if (a) Y is a subset of X, or (b)
X υ Y = R.
Slide 14-56
Multivalued Dependencies and
Fourth Normal Form (3)
Definition:
• A relation schema R is in 4NF with respect to a set of
dependencies F (that includes functional dependencies and
multivalued dependencies) if, for every nontrivial
multivalued dependency X —>> Y in F+, X is a superkey for R.
– Note: F+ is the (complete) set of all dependencies (functional
or multivalued) that will hold in every relation state r of R that
satisfies F. It is also called the closure of F.
Slide 14-57
Figure 14.15 Fourth and fifth
normal forms.
Figure 14.15
Fourth and fifth normal forms. (a) The EMP relation with two MVDs: Ename –>> Pname and Ename –>> Dname. (b) Decomposing the
EMP relation into two 4NF relations EMP_PROJECTS and EMP_DEPENDENTS. (c) The relation SUPPLY with no MVDs is in 4NF but not in
5NF if it has the JD(R1, R2, R3). (d) Decomposing the relation SUPPLY into the 5NF relations R1, R2, R3.
Slide 14- 48
6. Join Dependencies and Fifth
Normal Form (1)
Definition:
• A join dependency (JD), denoted by JD(R1, R2, ..., Rn), specified
on relation schema R, specifies a constraint on the states r of
R.
– The constraint states that every legal state r of R should have a
non-additive join decomposition into R1, R2, ..., Rn; that is, for
every such r we have
– * (R1(r), R2(r), ..., Rn(r)) = r
Note: an MVD is a special case of a JD where n = 2.
• A join dependency JD(R1, R2, ..., Rn), specified on relation
schema R, is a trivial JD if one of the relation schemas Ri in
JD(R1, R2, ..., Rn) is equal to R.
Slide 14- 49
Join Dependencies and Fifth Normal
Form (2)
Definition:
• A relation schema R is in fifth normal form (5NF)
(or Project-Join Normal Form (PJNF)) with
respect to a set F of functional, multivalued, and
join dependencies if,
– for every nontrivial join dependency JD(R1, R2, ..., Rn) in
F+ (that is, implied by F),
• every Ri is a superkey of R.
• Discovering join dependencies in practical databases with
hundreds of relations is next to impossible. Therefore, 5NF is
rarely used in practice.
Slide 14- 50