Sei sulla pagina 1di 33

Exercise – T/F

The columns of a relation are sometimes


called “tuples.”
Keys are always unique.
A relation is in first normal form if all of its
non-key attributes are dependent on part
of the key.
The functional dependency noted as A 
B, means that the value of A can be
determined from the value of B.
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-1
Revised by IB & SAM, Fasilkom UI, 2005
Exercise – Multiple Choices
 Which of the following is known to be true from the
functional dependency shown as (A, B)  (C, D)?
a. A is the determinant of C
b. A and B together are determined by C and D together
c. A and B together determine D
d. C and D together determine A
e. A determines B
 Which of the following is not a requirement for 1NF?
a. cells must contain single values
b. all entries in a column must be of the same kind
c. no two rows may be identical
d. rows must be ordered by the value of the primary key
e. the order of the columns is insignificant

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-2
Revised by IB & SAM, Fasilkom UI, 2005
Further Normalization

The main reference of this presentation is the textbook and


PPT from : Elmasri & Navathe, Fundamental of Database
Systems, 4th edition, 2004, Chapter 11
Additional resources: presentation prepared by Prof Steven A.
Demurjian, Sr
(http://www.engr.uconn.edu/~steve/courses.html)

Copyright © 2004 Pearson Education, Inc.


Outline
BCNF
Multivalued Dependencies and Fourth
Normal Form

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-4
Revised by IB & SAM, Fasilkom UI, 2005
BCNF (Boyce-Codd Normal Form)

A relation schema R is in Boyce-Codd


Normal Form (BCNF) if whenever an FD X
-> A holds in R, then X is a superkey of R
 Each normal form is strictly stronger than the
previous one
 Every 2NF relation is in 1NF
 Every 3NF relation is in 2NF
 Every BCNF relation is in 3NF
 There exist relations that are in 3NF but not in BCNF
 The goal is to have each relation in BCNF (or 3NF)

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-5
Revised by IB & SAM, Fasilkom UI, 2005
Figure 10.12 Boyce-Codd normal form
(a) BCNF normalization of LOTS1A with the functional dependency FD2
being lost in the decomposition. (b) A schematic relation with FDs; it is in
3NF, but not in BCNF.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-6
Revised by IB & SAM, Fasilkom UI, 2005
Figure 10.13 a relation TEACH that
is in 3NF but not in BCNF

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-7
Revised by IB & SAM, Fasilkom UI, 2005
Achieving the BCNF by
Decomposition (1)
Two FDs exist in the relation TEACH:
fd1: { student, course} -> instructor
fd2: instructor -> course
{student, course} is a candidate key for this
relation and that the dependencies shown
follow the pattern in Figure 10.12 (b). So this
relation is in 3NF but not in BCNF

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-8
Revised by IB & SAM, Fasilkom UI, 2005
Achieving the BCNF by
Decomposition (2)
 Three possible decompositions for relation TEACH
1. {student, instructor} and {student, course}
2. {course, instructor } and {course, student}
3. {instructor, course } and {instructor, student}
 All three decompositions will lose fd1. We have to
settle for sacrificing the functional dependency
preservation. But we cannot sacrifice the non-additivity
property after decomposition.
 Out of the above three, only the 3rd decomposition will
not generate spurious tuples after join.(and hence has
the non-additivity property).

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-9
Revised by IB & SAM, Fasilkom UI, 2005
Comparing the Normal Forms
Poor Relational Schema Design
Developed as Stepping Stone
1NF
Eliminate partial FDs of
non-key attributes to key
Eliminate the
non-trivial 2NF
functional Eliminate transitive FDs of non-key
dependencies attributes to key
of non-key 3NF
attributes to Eliminate partial and transitive FDs of
key key attributes to key

BCNF Most 3NF are in BCNF - BCNF


Eliminates All Update Anomalies
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-10
Revised by IB & SAM, Fasilkom UI, 2005
Reflections on Normalization
Normalization
A Tool for Validating the Quality of the Schema,
Rather than Merely as a Method for Designing a
Relational Schema
 Promotes Each Concept of the Application Domain
Mapping to Exactly One Concept of the Schema
 Normalization Process
Actually a Process of Concept Separation
Concept Separation is Result of Applying a Top-down
Methodology for Producing a Schema Via Subsequent
Refinements and Decompositions

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-11
Revised by IB & SAM, Fasilkom UI, 2005
Relational DB Design Process
Normalization Process Focused on
Decomposition
Raises Number of Questions
How do we Decompose a Schema into a Desirable
Normal Form?
What Criteria Should the Decomposed Schemas
Follow in order to Preserve the Semantics of the
Original Schema?
Can we Guarantee the Decomposition’s Quality?
Can we Prevent the “Loss” of Information?
Are Dependencies Maintained in Decomposition?
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-12
Revised by IB & SAM, Fasilkom UI, 2005
Recall Transitive FD/Update Anomalies
R = ( U, F ) S# DName DHead
U = { S#, DName, DHead } S1 D1 John
S2 D1 Jonh
F = { S#→DName, S3 D2 Smith
DName →DHead } S4 D3 Black

S# → Dhead” is a Transitive FD


When S4 Graduates, Head Information of D3 Lost
Similarly, If D5 has No Students Yet, then the Head
Information cannot be Stored in this Database
Update Head of Any Department Requires an Update
to Every Student Enrolled in the Dept.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-13
Revised by IB & SAM, Fasilkom UI, 2005
What are Possible Decompositions?
R = ( U, F ) U = { S#, DName, DHead }
F = { S#→DName, DName →DHead }

S# DName DHead
S1
S2
D1
D1
John
John δ 1
Information Based
S3 D2 Smith
S4 D3 Black

 δ 1 = { R1(S#, ∅), R2(DName, ∅) , R3(DHead, ∅)}


 δ 1 is Neither Lossless nor FD-Preserving

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-14
Revised by IB & SAM, Fasilkom UI, 2005
What are Possible Decompositions?
R = ( U, F ) U = { S#, DName, DHead }
F = { S#→DName, DName →DHead }
S# DName S# DHead •Lossless Decomposition but
S1 D1 S1 John not Dependency-Preserving
S2 D1 S2 John δ 2 •DName→DHead is lost in
S3 D2 S3 Smith
S4 Black
the decomposition
D3 S4

 δ 2 = { R1({S# ,DName}, {S#→DName}),


R2({S#, DHead}, {S#→DHead})}

δ 2 is Lossless but not FD-Preserving


Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-15
Revised by IB & SAM, Fasilkom UI, 2005
What are Possible Decompositions?
R = ( U, F ) U = { S#, DName, DHead }
F = { S#→DName, DName →DHead }
S# DName DName DHead
S1 D1 D1 John Lossless & dependency-
S2 D1 D1 John δ 3 preserving decomposition
S3 D2 D2
S4 D3 D3

 δ 3 = { R1({S# ,DName}, {S# → DName})


R3({DName, DHead}, {Dname → DHead})}

δ 3 is both Lossless and FD-Preserving


Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-16
Revised by IB & SAM, Fasilkom UI, 2005
Summary of Normalization
1NF
Eliminate the Partial Functional
Dependencies of Non-prime
Lossless Decomposition Attributes to Key Attributes
and Dependency Preserving
2NF
Eliminate the Transitive
Functional Dependencies of
Non-prime Attributes to Key
Attributes

3NF
Eliminate the Partial and
Lossless Decomposition Transitive Functional
but not Dependency Dependencies of Prime (Key)
Preserving Attributes to Key

BCNF
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-17
Revised by IB & SAM, Fasilkom UI, 2005
The Entire Normalization Picture
1NF
Eliminate Partial FDs of
Non-prime Attributes to Key
2NF
Eliminate Transitive FDs of Non-
prime Attributes to Key
3NF
Eliminate Partial and Transitive FDs
of Prime Attributes to Key
BCNF
Eliminate Non-trivial and Non-
functional Multi-Valued Dependencies
4NF
Eliminate Join Dependencies that are
Not Implied by Candidate Key
5NF
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-18
Revised by IB & SAM, Fasilkom UI, 2005
What are Multi-Valued
Dependencies?
 Focused on the Concept of Multi-Valued Dependencies
 A MVD X →→ Y Indicates that a Value of X Corresponds
to Multiple Values of Y
 Consider EMP with MVDs:
 ENAME →→ PNAME (E works on many Project)
 ENAME →→ DNAME (E has many Dependents)

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-19
Revised by IB & SAM, Fasilkom UI, 2005
What is Fourth Normal Form (4NF)?
 A Relation Schema R is in Fourth Normal Form (4NF)
w.r.t Dependencies F (FD and MVD) if for every Non-
Trivial MVD X →→ Y in F+, X is a Superkey for R
 MVD X →→ Y in R is called trivial if
Y is subset of X, or
X U Y = R
 Reconsider EMP with MVDs:
ENAME →→ PNAME (E works on many P)
ENAME →→ DNAME (E has many Dependents)
 ENAME is Not a Superkey of R since Need Triple of
ENAME, PNAME, and DNAME to Distinguish
 We need to Decompose EMP!

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-20
Revised by IB & SAM, Fasilkom UI, 2005
Notes on FD
A functional dependency is trivial if it is
satisfied by all instances of a relation
E.g.
 customer-name, loan-number → customer-name
 customer-name → customer-name
In general, α → β is trivial if β ⊆ α

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-21
Revised by IB & SAM, Fasilkom UI, 2005
Decomposition into 4NF

ENAME →→ PNAME is Trivial MVD: ENAME ∪ PNAME is


Equal to EMP_PROJECTS (same for ENAME →→ DNAME)
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-22
Revised by IB & SAM, Fasilkom UI, 2005
Multivalued Dependencies and 4NF

Decomposing a relation state of EMP that is not in 4NF. (a) EMP relation with
additional tuples. (b) Two corresponding 4NF relations EMP_PROJECTS and
EMP_DEPENDENTS.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-23
Revised by IB & SAM, Fasilkom UI, 2005
Other Normalizations
You can read by yourself

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-24
Revised by IB & SAM, Fasilkom UI, 2005
Concluding Remarks
What have we Learned?
Guidelines for “Good” Relational Design
Avoiding Anomalies
Functional Dependencies Augment Schema
Normalization “Improves” Design
Lossless Joins and Dependency Preservation
Quick Look at 4NF (Informally)
How is the Chapter Related to the Project?
Phase I in the Project: submit on 31th March
Step 1: ER Diagram
Step 2: ER to Relational Mapping
Step 3: Relational Normalization (1,2,3 NF) which Includes
Identification of FDs!
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-25
Revised by IB & SAM, Fasilkom UI, 2005
Exercise 10.19
 Consider the following two sets of
functional dependencies F= {A ->C, AC
->D, E ->AD, E ->H} and G = {A ->CD, E
->AH}.
Check whether or not they are equivalent.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-26
Revised by IB & SAM, Fasilkom UI, 2005
Exercise 10.33
 Consider the following relation for published books:
 BOOK (Book_title, Authorname, Book_type, Listprice, Author_affil,
Publisher)
 Author_affil referes to the affiliation of the author. Suppose the
following dependencies exist:
 Book_title -> Publisher, Book_type
 Book_type -> Listprice
 Author_name -> Author-affil
 (a) What normal form is the relation in? Explain your answer.
 (b) Apply normalization until you cannot decompose the
relations further. State the reasons behind each
decomposition.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-27
Revised by IB & SAM, Fasilkom UI, 2005
Answer 10.19
To show equivalence, we prove that G is covered by F & F is covered
by G.
Proof that G is covered by F:
 {A} + = {A, C, D} (with respect to F),
which covers A ->CD in G
 {E} + = {E, A, D, H, C} (with respect to F),
which covers E ->AH in G
Proof that F is covered by G:
 {A} + = {A, C, D} (with respect to G), which covers A ->C in F
 {A, C} + = {A, C, D} (with respect to G), which covers AC ->D in F
 {E} + = {E, A, H, C, D} (with respect to G), which covers E ->AD and
E ->H in F

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-28
Revised by IB & SAM, Fasilkom UI, 2005
Answer10.33
 Given the relation
 Book(Book_title, Authorname, Book_type, Listprice,
Author_affil, Publisher)
 and the FDs
 Book_title . Publisher, Book_type
 Book_type . Listprice
 Authorname .Author_affil

 (a)The key for this relation is Book_title,Authorname. This


relation is in 1NF and not in
 2NF as no attributes are FFD on the key. It is also not in
3NF.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-29
Revised by IB & SAM, Fasilkom UI, 2005
Answer10.33 (cont)
(b) 2NF decomposition:
 Book0(Book_title, Authorname)
 Book1(Book_title, Publisher, Book_type, Listprice)
 Book2(Authorname, Author_affil)
This decomposition eliminates the partial dependencies.
3NF decomposition:
 Book0(Book_title, Authorname)
 Book1-1(Book_title, Publisher, Book_type)
 Book1-2(Book_type, Listprice)
 Book2(Authorname, Author_affil)
 This decomposition eliminates the transitive dependency of
Listprice

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-30
Revised by IB & SAM, Fasilkom UI, 2005
Exercise 10.7. Suppose we have the following requirements for a university
database that isused to keep track of students transcripts:
(a) The university keeps track of each student's name (SNAME), student number
(SNUM), social security number (SSSN), current address (SCADDR) and phone
(SCPHONE), permanent address (SPADDR) and phone (SPPHONE), birthdate
(BDATE), sex (SEX), class (CLASS) (freshman, sophomore, ..., graduate), major
department (MAJORDEPTCODE), minor department (MINORDEPTCODE) (if any),
and degree program (PROG) (B.A., B.S., ..., Ph.D.). Both ssn and student number
have unique values for each student.
(b) Each department is described by a name (DEPTNAME), department code
(DEPTCODE), office number (DEPTOFFICE), office phone (DEPTPHONE), and
college (DEPTCOLLEGE). Both name and code have unique values for each
department.
(c) Each course has a course name (CNAME), description (CDESC), code number
(CNUM), number of semester hours (CREDIT), level (LEVEL), and offering
department (CDEPT). The value of code number is unique for each course.
(d) Each section has an instructor (INSTUCTORNAME), semester (SEMESTER), year
(YEAR), course (SECCOURSE), and section number (SECNUM). Section numbers
distinguish different sections of the same course that are taught during the
same semester/year; its values are 1, 2, 3, ...; up to the number of sections
taught during each semester.
(e) A transcript refers to a student (SSSN), refers to a particular section, and grade
(GRADE).
Design DB Schema, show FD, & normalize into 3NF or BCNF

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-31
Revised by IB & SAM, Fasilkom UI, 2005
Answer: From the above description, we can presume that the
following functional dependencies hold on the attributes:
 FD1: {SSSN} -> {SNAME, SNUM, SCADDR, SCPHONE, SPADDR,
SPPHONE, BDATE, SEX, CLASS,MAJOR, MINOR, PROG}
 FD2: {SNUM} -> {SNAME, SSSN, SCADDR, SCPHONE, SPADDR,
SPPHONE, BDATE, SEX, CLASS,MAJOR, MINOR, PROG}
 FD3: {DEPTNAME} -> {DEPTCODE, DEPTOFFICE, DEPTPHONE,
DEPTCOLLEGE}
 FD4: {DEPTCODE} -> {DEPTNAME, DEPTOFFICE, DEPTPHONE,
DEPTCOLLEGE}
 FD5: {CNUM} -> {CNAME, CDESC, CREDIT, LEVEL, CDEPT}
 FD6: {SECCOURSE, SEMESTER, YEAR, SECNUM} ->
{INSTRUCTORNAME}
 FD7: {SECCOURSE, SEMESTER, YEAR, SECNUM, SSSN} –>
{GRADE}

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-32
Revised by IB & SAM, Fasilkom UI, 2005
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Slide 11-33
Revised by IB & SAM, Fasilkom UI, 2005

Potrebbero piacerti anche