Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slide 11-1 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 Exercise – T/F The columns of a.

Similar presentations


Presentation on theme: "Slide 11-1 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 Exercise – T/F The columns of a."— Presentation transcript:

1 Slide 11-1 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 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.

2 Slide 11-2 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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

3 Copyright © 2004 Pearson Education, Inc. Further Normalization The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4 th edition, 2004, Chapter 11 Additional resources: presentation prepared by Prof Steven A. Demurjian, Sr (http://www.engr.uconn.edu/~steve/courses.html)

4 Slide 11-4 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 Outline BCNF Multivalued Dependencies and Fourth Normal Form

5 Slide 11-5 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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)

6 Slide 11-6 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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.

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

8 Slide 11-8 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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

9 Slide 11-9 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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 3 rd decomposition will not generate spurious tuples after join.(and hence has the non-additivity property).

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

11 Slide 11-11 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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

12 Slide 11-12 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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?

13 Slide 11-13 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 S# DName DHead R = ( U, F ) U = { S#, DName, DHead } F = { S#  DName, DName  DHead } S1 S2 S3 S4 D1 D2 D3 John Jonh Smith Black Recall Transitive FD/Update Anomalies 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.

14 Slide 11-14 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 What are Possible Decompositions? S# S1 S2 S3 S4 D1 D2 D3 DHead John Smith Black DName   Information Based R = ( U, F ) U = { S#, DName, DHead } F = { S#  DName, DName  DHead }    = { R 1 (S#,  ), R 2 (DName,  R 3 (DHead,  )}   is Neither Lossless nor FD-Preserving

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

16 Slide 11-16 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 What are Possible Decompositions? S# DName S1 S2 S3 S4 D1 D2 D3 DName DHead John D1 D2 D3   Lossless & dependency- preserving decomposition R = ( U, F ) U = { S#, DName, DHead } F = { S#  DName, DName  DHead }   = { R 1 ({S#,DName}, {S#  DName}) R 3 ({DName, DHead}, {Dname  DHead})}   is both Lossless and FD-Preserving

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

18 Slide 11-18 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 The Entire Normalization Picture 1NF 2NF 3NF BCNF Eliminate Partial FDs of Non-prime Attributes to Key Eliminate Transitive FDs of Non-prime Attributes to Key Eliminate Partial and Transitive FDs of Prime Attributes to Key 4NF Eliminate Non-trivial and Non- functional Multi-Valued Dependencies 5NF Eliminate Join Dependencies that are Not Implied by Candidate Key

19 Slide 11-19 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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)

20 Slide 11-20 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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!

21 Slide 11-21 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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   

22 Slide 11-22 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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)

23 Slide 11-23 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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.

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

25 Slide 11-25 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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 31 th March Step 1: ER Diagram Step 2: ER to Relational Mapping Step 3: Relational Normalization (1,2,3 NF) which Includes Identification of FDs!

26 Slide 11-26 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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.

27 Slide 11-27 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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.

28 Slide 11-28 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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

29 Slide 11-29 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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.

30 Slide 11-30 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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

31 Slide 11-31 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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

32 Slide 11-32 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition 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}

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


Download ppt "Slide 11-1 Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Revised by IB & SAM, Fasilkom UI, 2005 Exercise – T/F The columns of a."

Similar presentations


Ads by Google