Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Basics of Functional Dependencies and Normalization for Relational.

Slides:



Advertisements
Similar presentations
Functional Dependencies and Normalization for Relational Databases
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
NORMALIZATION. Normalization Normalization: The process of decomposing unsatisfactory "bad" relations by breaking up their attributes into smaller relations.
Chapter 3 Notes. 3.1 Functional Dependencies A functional dependency is a statement that – two tuples of a relation that agree on some particular set.
Ch 10, Functional Dependencies and Normal forms
Functional Dependencies and Normalization for Relational Databases.
Ms. Hatoon Al-Sagri CCIS – IS Department Normalization.
Functional Dependencies and Normalization for Relational Databases
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Basics of Functional Dependencies and Normalization for Relational.
Part 6 Chapter 15 Normalization of Relational Database Csci455 r 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
METU Department of Computer Eng Ceng 302 Introduction to DBMS Functional Dependencies and Normalization for Relational Databases by Pinar Senkul resources:
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Basics of Functional Dependencies and Normalization for Relational.
Chapter 8 Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Functional Dependencies and Normalization for Relational Databases.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 6 NORMALIZATION FOR RELATIONAL DATABASES Instructor Ms. Arwa Binsaleh.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
King Saud University College of Computer & Information Sciences Computer Science Department CS 380 Introduction to Database Systems Functional Dependencies.
Normalization. Learners Support Publications 2 Objectives u The purpose of normalization. u The problems associated with redundant data.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Normalization for Relational Databases.
DatabaseIM ISU1 Chapter 10 Functional Dependencies and Normalization for RDBs Fundamentals of Database Systems.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Topic 10 Functional Dependencies and Normalization for Relational Databases Faculty of Information Science and Technology Mahanakorn University of Technology.
Instructor: Churee Techawut Functional Dependencies and Normalization for Relational Databases Chapter 4 CS (204)321 Database System I.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 4 Normalization.
Functional Dependencies and Normalization for Relational Databases.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Chapter Functional Dependencies and Normalization for Relational Databases.
CSE314 Database Systems Basics of Functional Dependencies and Normalization for Relational Databases Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E.
Functional Dependencies and Normalization Jose M. Peña
1 Functional Dependencies and Normalization Chapter 15.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Lecture 8: Database Concepts May 4, Outline From last lecture: creating views Normalization.
1 CSE 480: Database Systems Lecture 18: Normal Forms and Normalization.
Design Process - Where are we?
Dr. Mohamed Osman Hegaz1 Logical data base design (2) Normalization.
Normalization. 2 u Main objective in developing a logical data model for relational database systems is to create an accurate representation of the data,
Lecture 3 Functional Dependency and Normal Forms Prof. Sin-Min Lee Department of Computer Science.
Chapter 7 Functional Dependencies Copyright © 2004 Pearson Education, Inc.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 5 Introduction to a First Course in Database Systems.
Al-Imam University Girls Education Center Collage of Computer Science 1 st Semester, 1432/1433H Chapter 10_part 1 Functional Dependencies and Normalization.
11/06/97J-1 Principles of Relational Design Chapter 12.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Functional Dependencies and Normalization for Relational Databases.
Al-Imam University Girls Education Center Collage of Computer Science 1 nd Semester, 1432/1433H Chapter 10_part2 Functional Dependencies and Normalization.
Chapter 15 1 Functional Dependencies and Normalization for Relational Databases تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة من الادوات في.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Chapter 14 Functional Dependencies and Normalization Informal Design Guidelines for Relational Databases –Semantics of the Relation Attributes –Redundant.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Functional Dependencies and Normalization for Relational Databases تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة من الادوات في ذلك. حيث المرجع.
10/3/2017.
Functional Dependency and Normalization
Functional Dependencies and Normalization for Relational Databases
Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases.
Functional Dependencies and Normalization for RDBs
Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases.
Database Management systems Subject Code: 10CS54 Prepared By:
Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases.
Chapter Outline 1 Informal Design Guidelines for Relational Databases
Presentation transcript:

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Chapter 15 Outline  Informal Design Guidelines for Relation Schemas  Functional Dependencies  Normal Forms Based on Primary Keys  General Definitions of Second and Third Normal Forms  Boyce-Codd Normal Form

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Chapter 15 Outline (cont’d.)  Multivalued Dependency and Fourth Normal Form  Join Dependencies and Fifth Normal Form

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Introduction  Levels at which we can discuss goodness of relation schemas  Logical (or conceptual) level  Implementation (or physical storage) level  Approaches to database design:  Bottom-up – given a set of data structures  Top-down – given a set requirements

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Informal Design Guidelines for Relation Schemas  Measures of quality  Making sure attribute semantics are clear  Reducing redundant information in tuples  Reducing NULL values in tuples  Disallowing possibility of generating spurious tuples

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Imparting Clear Semantics to Attributes in Relations  Semantics of a relation  Meaning resulting from interpretation of attribute values in a tuple  Easier to explain semantics of relation  Indicates better schema design

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Continues…

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Guideline 1  Design relation schema so that it is easy to explain its meaning  Do not combine attributes from multiple entity types and relationship types into a single relation  Example of violating Guideline 1: Figure 15.3

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Guideline 1 (cont’d.)

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Redundant Information in Tuples and Update Anomalies  Grouping attributes into relation schemas  Significant effect on storage space  Storing natural joins of base relations leads to update anomalies  Types of update anomalies:  Insertion  Deletion  Modification

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Guideline 2  Design base relation schemas so that no update anomalies are present in the relations  If any anomalies are present:  Note them clearly  Make sure that the programs that update the database will operate correctly  Example of violating Guideline 2: Figure 15.4

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright © 2011 Ramez Elmasri and Shamkant Navathe NULL Values in Tuples  May group many attributes together into a “fat” relation  Can end up with many NULLs  Problems with NULLs  Wasted storage space  Problems understanding meaning

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Guideline 3  Avoid placing attributes in a base relation whose values may frequently be NULL  If NULLs are unavoidable:  Make sure that they apply in exceptional cases only, not to a majority of tuples

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Example  If only 15% of employees have individual offices, there is little justification for including an attribute Office_number in EMPLOYEE.  Rather, a relation EMP_OFFICES(Essn, Office_number) can be created to include tuples for only the employees with individual offices.

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Generation of Spurious Tuples  Figure 15.5(a)  Relation schemas EMP_LOCS and EMP_PROJ1  NATURAL JOIN  Result produces many more tuples than the original set of tuples in EMP_PROJ  Called spurious tuples  Represent spurious information that is not valid

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Guideline 4  Design relation schemas to be joined with equality conditions on attributes that are appropriately related  Guarantees that no spurious tuples are generated  Avoid relations that contain matching attributes that are not (foreign key, primary key) combinations  Example of violating Guideline 4: Figure 15.5 and 15.6

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Summary and Discussion of Design Guidelines  Anomalies cause redundant work to be done  Waste of storage space due to NULLs  Difficulty of performing operations and joins due to NULL values  Generation of invalid and spurious data during joins

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Functional Dependencies  Formal tool for analysis of relational schemas  Enables us to detect and describe some of the above-mentioned problems in precise terms  Theory of functional dependency

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Definition of Functional Dependency  Constraint between two sets of attributes from the database  Property of semantics or meaning of the attributes  Legal relation states  Satisfy the functional dependency constraints

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Definition of Functional Dependency (cont’d.)  Given a populated relation  Cannot determine which FDs hold and which do not  Unless meaning of and relationships among attributes known  Can state that FD does not hold if there are tuples that show violation of such an FD

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Normal Forms Based on Primary Keys  Normalization process  Approaches for relational schema design  Perform a conceptual schema design using a conceptual model then map conceptual design into a set of relations  Design relations based on external knowledge derived from existing implementation of files or forms or reports

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Normalization of Relations  Takes a relation schema through a series of tests  Certify whether it satisfies a certain normal form  Proceeds in a top-down fashion  Normal form tests

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Normalization of Relations (cont’d.)  Properties that the relational schemas should have:  Nonadditive join property Extremely critical  Dependency preservation property Desirable but sometimes sacrificed for other factors

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Practical Use of Normal Forms  Normalization carried out in practice  Resulting designs are of high quality and meet the desirable properties stated previously  Pays particular attention to normalization only up to 3NF, BCNF, or at most 4NF  Do not need to normalize to the highest possible normal form

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Definitions of Keys and Attributes Participating in Keys  Definition of superkey and key  Candidate key  If more than one key in a relation schema One is primary key Others are secondary keys

Copyright © 2011 Ramez Elmasri and Shamkant Navathe First Normal Form  Part of the formal definition of a relation in the basic (flat) relational model  Only attribute values permitted are single atomic (or indivisible) values  Techniques to achieve first normal form  Remove attribute and place in separate relation  Expand the key  Use several atomic attributes

Copyright © 2011 Ramez Elmasri and Shamkant Navathe First Normal Form (cont’d.)  Does not allow nested relations  In a nested relation, each tuple can have a relation within it  To change to 1NF:  Remove nested relation attributes into a new relation  Propagate the primary key into it  Unnest relation into a set of 1NF relations

Copyright © 2011 Ramez Elmasri and Shamkant Navathe

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Second Normal Form  Based on concept of full functional dependency  Versus partial dependency  Second normalize into a number of 2NF relations  Nonprime attributes are associated only with part of primary key on which they are fully functionally dependent

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Full Functional Dependency vs. Partial Dependency  A functional dependency X -> Y is a full functional dependency if removal of any attribute from X means that the dependency does not hold any more. Ex. {Ssn, Pnumber} -> Hours (Figure 15.11(a))  A functional dependency X -> Y is a partial dependency if some attribute A in X can be removed from X and the dependency still holds.  Ex. {Ssn, Pnumber} -> Ename (Figure 15.11(a))

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Third Normal Form  A functional dependency X->Y in a relation schema R is a transitive dependency if there exists a set of attributes Z in R that is neither a candidate key nor a subset of any key of R, and both X->Z and Z->Y hold.  Based on concept of transitive dependency  Difference: given FD X->Y  Left-hand side X is part of primary key (violates 2NF)  Left-hand side X is a nonkey attribute (violates 3NF)

Copyright © 2011 Ramez Elmasri and Shamkant Navathe General Definitions of Second and Third Normal Forms

Copyright © 2011 Ramez Elmasri and Shamkant Navathe General Definitions of Second and Third Normal Forms (cont’d.)  Prime attribute  Part of any candidate key will be considered as prime  Consider partial, full functional, and transitive dependencies with respect to all candidate keys of a relation

Copyright © 2011 Ramez Elmasri and Shamkant Navathe General Definition of Second Normal Form

Copyright © 2011 Ramez Elmasri and Shamkant Navathe

General Definition of Third Normal Form

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Boyce-Codd Normal Form  Every relation in BCNF is also in 3NF  Relation in 3NF is not necessarily in BCNF  Difference:  Condition which allows A to be prime is absent from BCNF  Most relation schemas that are in 3NF are also in BCNF

Copyright © 2011 Ramez Elmasri and Shamkant Navathe

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Assume the following FD: Student, Course ->Instructor Instructor->Course

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Multivalued Dependency and Fourth Normal Form  Multivalued dependency (MVD)  Consequence of first normal form (1NF)  Notes:  X->> Y implies X->>Z  t1,t2,t3,t4 are not necessarily distinct.

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Multivalued Dependency and Fourth Normal Form (cont’d.)  Relations containing nontrivial MVDs  They tend to be all-key relations  Fourth normal form (4NF)  Violated when a relation has undesirable multivalued dependencies

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Join Dependencies and Fifth Normal Form  Join dependency  Multiway decomposition into fifth normal form (5NF)  Very peculiar semantic constraint  Normalization into 5NF is very rarely done in practice

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Join Dependencies and Fifth Normal Form (cont’d.)

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Summary  Informal guidelines for good design  Functional dependency  Basic tool for analyzing relational schemas  Normalization:  1NF, 2NF, 3NF, BCNF, 4NF, 5NF

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Exercise 1 Consider a relation R(A, B, C, D), with FDs AB -> C, BC -> D, CD -> A.  (a) Find the closure of AB.  (b) Is R a good schema?  (c) If we decompose R as R1(A,B,C) and R2(A,C,D). Is it a good decomposition?

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Exercise 2  Consider relation R(A,B,C,D,E) with the following functional dependencies: AB -> C, D -> E, DE -> B.  Is R in BCNF? If not, decompose R into a collection of BCNF relations.

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Exercise 3  “Any two-attribute relation is in BCNF.” Is it correct?

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Exercise 4 Compute the closure of the following set F of functional dependencies for relation schema R = {A, B, C, D, E}. A -> BC CD -> E B -> D E -> A List the candidate keys for R.

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Exercise 5 Consider a relation R(A,B,C,D,E) with the following dependencies: {AB-> C, CD -> E, DE -> B} List all candidate keys.

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Exercise 6 R(A,B,C,D) and FDs {AB -> C, C -> D, D -> A}. (1) List all nontrivial FDs that can be inferred from the given FDs. (2) Find all candidate keys. (3) Find all BCNF violations. (4) Decompose R into relations in BCNF. (5) What FDs are not preserved by BCNF.