CS 405G: Introduction to Database Systems 18. Normal Forms and Normalization.

Slides:



Advertisements
Similar presentations
Schema Refinement: Normal Forms
Advertisements

Schema Refinement and Normal Forms Given a design, how do we know it is good or not? What is the best design? Can a bad design be transformed into a good.
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.
NORMALIZATION FIRST NORMAL FORM (1NF): A relation R is in 1NF if all attributes have atomic value = one value for an attribute = no repeating groups =
Functional Dependencies and Normalization for Relational Databases.
Review Applications of Database Systems Applications of Database Systems Theory Practice.
Normalization Normalization We discuss four normal forms: first, second, third, and Boyce-Codd normal forms 1NF, 2NF, 3NF, and BCNF Normalization.
Jump to first page Normalization Jump to first page Topics n Why normalization is needed n What causes anomalies n What the 4 normal forms are n How.
Chapter 8 Normal Forms Based on Functional Dependencies Deborah Costa Oct 18, 2007.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1 Database Design Theory Which tables to have in a database Normalization.
Database Normalization Il-Han Yoo CS 157A Professor: Sin-Min Lee.
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
Databases 6: Normalization
NORMALIZATION N. HARIKA (CSC).
Introduction to Schema Refinement
Normalization B Database Systems Normal Forms Wilhelm Steinbuss Room G1.25, ext. 4041
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Copyright © Curt Hill Schema Refinement III 4 th NF and 5 th NF.
Copyright, Harris Corporation & Ophir Frieder, Normal Forms “Why be normal?” - Author unknown Normal.
IT420: Database Management and Organization Normalization 31 January 2006 Adina Crăiniceanu
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
Database Management COP4540, SCS, FIU Relation Normalization (Chapter 14)
Announcements Read 5.8 – 5.13 for Monday Project Step 3, due Monday 10/18 Homework 4, due Friday 10/15 – by (or turn in Monday in class)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Normalization for Relational Databases.
Database Normalization.
DatabaseIM ISU1 Chapter 10 Functional Dependencies and Normalization for RDBs Fundamentals of Database Systems.
Schema Refinement and Normal Forms 20131CS3754 Class Notes #7, John Shieh.
Chapter 7 1 Database Principles Data Normalization Primarily a tool to validate and improve a logical design so that it satisfies certain constraints that.
CS143 Review: Normalization Theory Q: Is it a good table design? We can start with an ER diagram or with a large relation that contain a sample of the.
Normal Forms through BCNF CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Functional Dependencies and Normalization for Relational Databases.
Normalization Well structured relations and anomalies Normalization First normal form (1NF) Functional dependence Partial functional dependency Second.
By Abdul Rashid Ahmad. E.F. Codd proposed three normal forms: The first, second, and third normal forms 1NF, 2NF and 3NF are based on the functional dependencies.
Functional Dependencies and Normalization 1 Instructor: Mohamed Eltabakh
Lecture No 14 Functional Dependencies & Normalization ( III ) Mar 04 th 2011 Database Systems.
CS 405G: Introduction to Database Systems 25 Exercise Chen Qian University of Kentucky.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#16: Schema Refinement & Normalization.
Normalization Sept. 2012ACS-3902 Yangjun Chen1 Outline: Normalization Chapter 14 – 3rd ed. (Chap. 10 – 4 th, 5 th ed.; Chap. 6, 6 th ed.) Redundant information.
1 CSE 480: Database Systems Lecture 18: Normal Forms and Normalization.
CS 405G: Introduction to Database Systems
Normalization. 2 u Main objective in developing a logical data model for relational database systems is to create an accurate representation of the data,
Normalization Sept. 2014ACS-3902 Yangjun Chen1 Outline: Normalization Redundant information and update anomalies Function dependencies Normal forms -1NF,
Normalization.
Review Database Application Development Access Database Development Theory Practice.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
CS 405G: Introduction to Database Systems Database Normalization.
CS 338Database Design and Normal Forms9-1 Database Design and Normal Forms Lecture Topics Measuring the quality of a schema Schema design with normalization.
Ch 7: Normalization-Part 1
© D. Wong Functional Dependencies (FD)  Given: relation schema R(A1, …, An), and X and Y be subsets of (A1, … An). FD : X  Y means X functionally.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
Database Design Theory CS405G: Introduction to Database Systems Jinze Liu 3/15/20161.
Objectives of Normalization  To create a formal framework for analyzing relation schemas based on their keys and on the functional dependencies among.
Copyright © Curt Hill Schema Refinement II 2 nd NF to 3 rd NF to BCNF.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
CS 405G: Introduction to Database Systems 13b Exercise Chen Qian University of Kentucky.
Chapter 14 Functional Dependencies and Normalization Informal Design Guidelines for Relational Databases –Semantics of the Relation Attributes –Redundant.
Functional Dependencies and Normalization for Relational Databases تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة من الادوات في ذلك. حيث المرجع.
COP 6726: New Directions in Database Systems
Normalization Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 19.
Functional Dependency and Normalization
Normalization There is a sequence to normal forms:
Normalization Normalization
Outline: Normalization
CS 405G: Introduction to Database Systems
Database Design Theory CS405G: Introduction to Database Systems
Database Normalization
Presentation transcript:

CS 405G: Introduction to Database Systems 18. Normal Forms and Normalization

How to connect MySQL server Know your user id and password (provided by Paul Linton) Server installed on mysql.cs.uky.edu 10/13/2015Chen Univ of Kentucky

10/13/2015Chen Univ of Kentucky

10/13/2015Chen Univ of Kentucky

10/13/2015Chen Univ of Kentucky

10/13/2015Chen University of Kentucky Last class Functional Dependency. Normalization Decomposition 6

Review Functional dependencies X -> Y: X “determines” Y If two rows agree on X, they must agree on Y 10/13/ Attribute on the LHS is known as the determinant X is a determinant of Y

10/13/2015Chen University of Kentucky8 Normalization A normalization is the process of organizing the fields and tables of a relational database to minimize redundancy and dependency. A normal form is a certification that tells whether a relation schema is in a particular state

First Normal Form ( 1NF ) A relation is in first normal form if the domain of each attribute contains only atomic values, and the value of each attribute contains only a single value from that domain. 10/13/2015Chen University of Kentucky9

10/13/2015Chen University of Kentucky10 2 nd Normal Form An attribute A of a relation R is a nonprimary attribute if it is not part of any key in R, otherwise, A is a primary attribute. R is in (general) 2 nd normal form if every nonprimary attribute A in R is not partially functionally dependent on any key of R

Redundancy Example If a key will result a partial dependency of a nonprimary attribute. e.g. EID, PID -> Ename In this case, the attribute (Ename) should be separated with its full dependency key (EID) to be a new table. So, to check whether a table includes redundancy. Try every nonprimary attribute and check whether it fully depends on any key. 10/13/2015Chen University of Kentucky11

10/13/2015Chen University of Kentucky12 Decomposition Decomposition eliminates redundancy To get back to the original relation, use natural join. EIDPIDEname PnameHours John platform Ben 12349John Susan platform40 Decomposition EIDEname 1234John 1123Ben 1023Susan EIDPIDPnameHours B2B platform CRM CRM B2B platform40 Foreign key

10/13/2015Chen University of Kentucky13 Decomposition Decomposition may be applied recursively EIDPIDPnameHours B2B platform CRM CRM B2B platform40 PIDPname 10B2B platform 9CRM EIDPIDHours

10/13/2015Chen University of Kentucky14 Questions about decomposition When to decompose How to come up with a correct decomposition (i.e., lossless join decomposition)

Third normal form 3NF requires that there are no non-trivial functional dependencies of non-key attributes on something other than a superset of a candidate key. Recall: non-trivial FD means LHS has no intersection with RHS. In summary, all non-key attributes are mutually independent. 10/13/2015Chen University of Kentucky15

Ename and has no FD 10/13/2015Chen University of Kentucky16 EIDEname 1234John 1123Ben 1023Susan

Boyce-Codd normal form (BCNF) BCNF requires that there are no non-trivial functional dependencies of attributes on something other than a superset of a candidate key (called a superkey). All attributes are dependent on a key, a whole key and nothing but a key (excluding trivial dependencies, like A->A). 10/13/2015Chen University of Kentucky17

A table is said to be in the BCNF if and only if it is in the 3NF and every non-trivial, left- irreducible functional dependency has a candidate key as its determinant. In more informal terms, a table is in BCNF if it is in 3NF and the only determinants are the candidate keys. 10/13/2015Chen University of Kentucky18

10/13/2015Chen University of Kentucky19 Non-key FD’s Consider a non-trivial FD X -> Y where X is not a super key Since X is not a super key, there are some attributes (say Z) that are not functionally determined by X That b is always associated with a is recorded by multiple rows: redundancy, update anomaly, deletion anomaly XYZ abc abd

10/13/2015Chen University of Kentucky20 Dealing with Nonkey Dependency: BCNF A relation R is in Boyce-Codd Normal Form if For every non-trivial FD X -> Y in R, X is a super key That is, all FDs follow from “key -> other attributes” When to decompose As long as some relation is not in BCNF How to come up with a correct decomposition Always decompose on a BCNF violation (details next)  Then it is guaranteed to be a lossless join decomposition

10/13/2015Chen University of Kentucky21 BCNF decomposition algorithm Find a BCNF violation That is, a non-trivial FD X -> Y in R where X is not a super key of R Decompose R into R 1 and R 2, where R 1 has attributes X Y R 2 has attributes X Z, where Z contains all attributes of R that are in neither X nor Y (i.e. Z = attr(R) – X – Y) Repeat until all relations are in BCNF

10/13/2015Chen University of Kentucky22 BCNF decomposition example WorkOn (EID, Ename, , PID, hours) BCNF violation: EID -> Ename, Student (EID, Ename, ) Grade (EID, PID, hours) BCNF

10/13/2015Chen University of Kentucky23 Another example WorkOn (EID, Ename, , PID, hours) BCNF violation: -> EID StudentID ( , EID) StudentGrade’ ( , Ename, PID, hours) BCNF BCNF violation: -> Ename StudentName ( , Ename) Grade ( , PID, hours) BCNF

10/13/2015Chen University of Kentucky24 Exercise Property(Property_id#, County_name, Lot#, Area, Price, Tax_rate) Property_id# -> County_name, Lot#, Area, Price, Tax_rate County_name, Lot# -> Property_id#, Area, Price, Tax_rate County_name -> Tax_rate area -> Price

10/13/2015Chen University of Kentucky25 Exercise Property(Property_id#, County_name, Lot#, Area, Price, Tax_rate) BCNF violation: County_name -> Tax_rate LOTS1 (County_name, Tax_rate ) LOTS2 (Property_id#, County_name, Lot#, Area, Price) BCNF violation: Area -> Price LOTS2A (Area, Price) LOTS2B (Property_id#, County_name, Lot#, Area) BCNF

10/13/2015Chen University of Kentucky26 Why is BCNF decomposition lossless Given non-trivial X -> Y in R where X is not a super key of R, need to prove: Anything we project always comes back in the join: R π XY ( R ) π XZ ( R ) Sure; and it doesn’t depend on the FD Anything that comes back in the join must be in the original relation: R π XY ( R ) π XZ ( R ) Proof makes use of the fact that X -> Y

10/13/2015Chen University of Kentucky27 Recap Functional dependencies: a generalization of the key concept Partial dependencies: a source of redundancy Use 2 nd Normal form to remove partial dependency Non-key functional dependencies: a source of redundancy BCNF decomposition: a method for removing ALL functional dependency related redundancies Plus, BNCF decomposition is a lossless join decomposition

Normalization 10/13/ There is a sequence to normal forms: 1NF is considered the weakest, 2NF is stronger than 1NF, 3NF is stronger than 2NF, and BCNF is considered the strongest Also, any relation that is in BCNF, is in 3NF; any relation in 3NF is in 2NF; and any relation in 2NF is in 1NF.

Normalization 10/13/ BCNF 3NF 2NF 1NF a relation in BCNF, is also in 3NF a relation in 3NF is also in 2NF a relation in 2NF is also in 1NF

First Normal Form 10/13/ The following is not in 1NF EmpNumEmpPhoneEmpDegrees BA, BSc, PhD BSc, MSc EmpDegrees is a multi-valued field: employee 679 has two degrees: BSc and MSc employee 333 has three degrees: BA, BSc, PhD

First Normal Form 10/13/ EmpNumEmpDegree 333BA 333BSc 333PhD 679BSc MSc679 EmpNumEmpPhone An outer join between Employee and EmployeeDegree will produce the information we saw before Employee EmployeeDegree

Second Normal Form 10/13/ LineNumProdNumQtyInvNum InvNum, LineNumProdNum InvNum, ProdNumLineNum Since there is a determinant that is not a candidate key, InvLine is not BCNF InvLine is not 2NF since there is a partial dependency of InvDate on InvNum Qty InvDate InvNum There are two candidate keys. Qty is the only non- key attribute, and it is dependent on InvNum InvLine is only in 1NF Consider this InvLine table (in 1NF):

Second Normal Form 10/13/ LineNumProdNumQtyInvNumInvDate InvLine 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: LineNumProdNumQtyInvNum InvDateInvNum

Third Normal Form 10/13/ EmpNumEmpNameDeptNumDeptName EmpName, DeptNum, and DeptName are non-key attributes. DeptNum determines DeptName, a non-key attribute, and DeptNum is not a candidate key. Consider this Employee relation Is the relation in 3NF? … no Is the relation in 2NF? … yes Is the relation in BCNF? … no Candidate keys are? …

Third Normal Form 10/13/ EmpNumEmpNameDeptNumDeptName We correct the situation by decomposing the original relation into two 3NF relations. Note the decomposition is lossless. EmpNumEmpNameDeptNumDeptNameDeptNum Verify these two relations are in 3NF. Are they in BCNF?

Boyce-Codd Normal Form 10/13/ Boyce-Codd Normal Form BCNF is defined very simply: a relation is in BCNF if it is in 1NF and if every determinant is a candidate key.

student_nocourse_noinstr_no Instructor teaches one course only. Student takes a course and has one instructor. In 3NF, but not in BCNF: {student_no, course_no}  instr_no instr_no  course_no since we have instr_no  course-no, but instr_no is not a Candidate key. 10/13/

course_noinstr_no student_noinstr_no student_nocourse_noinstr_no BCNF {student_no, instr_no}  student_no {student_no, instr_no}  instr_no instr_no  course_no 10/13/

Boyce-Codd Normal Form 10/13/ LineNumProdNumQtyInvNum InvNum, LineNumProdNum InvNum, ProdNumLineNum There are two candidate keys. Since every determinant is a candidate key, the relation is in BCNF This relation is about Invoice lines only. Qty {InvNum, LineNum} and {InvNum, ProdNum} are the two candidate keys.

inv_noline_noprod_noprod_descqty 10/13/

2NF, but not in 3NF, nor in BCNF: inv_noline_noprod_noprod_descqty since prod_no is not a candidate key and we have: prod_no  prod_desc. 10/13/

EmployeeDept enamessnbdateaddressdnumberdname 10/13/

Summary Philosophy behind BCNF, 4NF: Data should depend on the key, the whole key, and nothing but the key! Philosophy behind 3NF: … But not at the expense of more expensive constraint enforcement! 10/13/

Next Class Quiz again 10/13/2015Chen University of Kentucky44