Murali Mani Normalization. Murali Mani What and Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert,

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Advertisements

Normalization 1 Instructor: Mohamed Eltabakh Part II.
ALAK ROY. Assistant Professor Dept. of CSE NIT Agartala N ATIONAL I NSTITUTE OF T ECHNOLOGY A GARTALA Aug-Dec,2010 Normalization 2 CSE-503 :: D ATABASE.
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.
Functional Dependencies and Normalization for Relational Databases.
CS Schema Refinement and Normal Forms Chapter 19.
Murali Mani The Relational Model. Murali Mani Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still.
Nov 11, 2003Murali Mani Normalization B term 2004: lecture 7, 8, 9.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Cs3431 Normalization. cs3431 Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert, delete and update.
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.
Cs3431 Normalization Part II. cs3431 Attribute Closure : Example Consider R (A, B, C, D, E) with FDs A  B, B  C, CD  E Does A  E hold ? (Is A  E.
Boyce-Codd NF & Lossless Decomposition Professor Sin-Min Lee.
Chapter 14 Advanced Normalization Transparencies © Pearson Education Limited 1995, 2005.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Functional Dependencies and Normalization 1 Instructor: Mohamed Eltabakh
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
King Saud University College of Computer & Information Sciences Computer Science Department CS 380 Introduction to Database Systems Functional Dependencies.
Lecture 6 Normalization: Advanced forms. Objectives How inference rules can identify a set of all functional dependencies for a relation. How Inference.
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.
Schema Refinement and Normal Forms Chapter 19 1 Database Management Systems 3ed, R.Ramakrishnan & J.Gehrke.
Instructor: Churee Techawut Functional Dependencies and Normalization for Relational Databases Chapter 4 CS (204)321 Database System I.
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.
SCUJ. Holliday - coen 1784–1 Schedule Today: u Normal Forms. u Section 3.6. Next u Relational Algebra. Read chapter 5 to page 199 After that u SQL Queries.
Functional Dependencies and Normalization 1 Instructor: Mohamed Eltabakh
Chapter Functional Dependencies and Normalization for Relational Databases.
Revisit FDs & BCNF Normalization 1 Instructor: Mohamed Eltabakh
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
1 Schema Refinement and Normal Forms Week 6. 2 The Evils of Redundancy  Redundancy is at the root of several problems associated with relational schemas:
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1 CSE 480: Database Systems Lecture 18: Normal Forms and Normalization.
Chapter 7 Functional Dependencies Copyright © 2004 Pearson Education, Inc.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
© 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.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
Chapter 14 Functional Dependencies and Normalization Informal Design Guidelines for Relational Databases –Semantics of the Relation Attributes –Redundant.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Functional Dependencies and Normalization 1 Instructor: Mohamed Eltabakh Part 2.
COP 6726: New Directions in Database Systems
Normalization Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 19.
Functional Dependency and Normalization
Advanced Normalization
Schedule Today: Next After that Normal Forms. Section 3.6.
Schema Refinement and Normal Forms
Normalization First Normal Form (1NF) Boyce-Codd Normal Form (BCNF)
Advanced Normalization
Functional Dependencies and Normalization
Database Management systems Subject Code: 10CS54 Prepared By:
Normalization Murali Mani.
Functional Dependencies and Normalization
Functional Dependencies and Normalization
Normalization.
Normalization Part II cs3431.
Functional Dependencies and Normalization
Normalization cs3431.
Instructor: Mohamed Eltabakh
Chapter 19 (part 1) Functional Dependencies
Instructor: Mohamed Eltabakh
Functional Dependencies and Normalization
Functional Dependencies and Normalization
Presentation transcript:

Murali Mani Normalization

Murali Mani What and Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert, delete and update Normalization uses concept of dependencies Functional Dependencies Idea used: Decomposition Break R (A, B, C, D) into R1 (A, B) and R2 (B, C, D) Use decomposition judiciously.

Murali Mani Insert Anomaly sNumbersNamepNumberpName s1Davep1MM s2Gregp2ER Student Note: We cannot insert a professor who has no students. Insert Anomaly: We are not able to insert “valid” value/(s)

Murali Mani Delete Anomaly sNumbersNamepNumberpName s1Davep1MM s2Gregp2ER Student Note: We cannot delete a student that is the only student of a professor. Note: In both cases, minimum cardinality of Professor in the corresponding ER schema is 0 Delete Anomaly: We are not able to perform a delete without losing some “valid” information.

Murali Mani Update Anomaly sNumbersNamepNumberpName s1Davep1MM s2Gregp1MM Student Note: To update the name of a professor, we have to update in multiple tuples. Update anomalies are due to redundancy. Note the maximum cardinality of Professor in the corresponding ER schema is * Update Anomaly: To update a value, we have to update multiple rows.

Murali Mani Keys : Revisited A key for a relation R (a1, a2, …, an) is a set of attributes, K that uniquely determine the values for all attributes of R. A key K is minimal: no proper subset of K is a key. A superkey need not be minimal Prime Attribute: An attribute of a key

Murali Mani Keys: Example sNumbersNameaddress 1Dave144FL 2Greg320FL Student Primary Key: Candidate key: Some superkeys: {,, } Prime Attribute: {sNumber, sName}

Murali Mani Functional Dependencies (FDs) sNumbersNameaddress 1Dave144FL 2Greg320FL Student Suppose we have the FD sName  address for any two rows in the Student relation with the same value for sName, the value for address must be the same i.e., there is a function from sName to address Note: We will assume no null values. Any key (primary or candidate) or superkey of a relation R functionally determines all attributes of R

Murali Mani Properties of FDs Consider A, B, C, Z are sets of attributes Reflexive (also called trivial FD): if A  B, then A  B Transitive: if A  B, and B  C, then A  C Augmentation: if A  B, then AZ  BZ Union: if A  B, A  C, then A  BC Decomposition: if A  BC, then A  B, A  C

Murali Mani Inferring FDs Why? Suppose we have a relation R (A, B, C) and we have functional dependencies A  B, B  C, C  A what is a key for R? Should we split R into multiple relations? We can infer A  ABC, B  ABC, C  ABC. Hence A, B, C are all keys.

Murali Mani Algorithm for inference of FDs Computing the closure of set of attributes {A1, A2, …, An}, denoted {A1, A2, …, An} + 1. Let X = {A1, A2, …, An} 2. If there exists a FD B1, B2, …, Bm  C, such that every Bi  X, then X = X  C 3. Repeat step 2 till no more attributes can be added. 4. {A1, A2, …, An} + = X

Murali Mani Inferring FDs: Example 1 Given R (A, B, C), and FDs A  B, B  C, C  A, what are possible keys for R Compute the closure of attributes: {A} + = {A, B, C} {B} + = {A, B, C} {C} + = {A, B, C} So keys for R are,,

Murali Mani Inferring FDs: Example 2 Consider R (A, B, C, D, E) with FDs A  B, B  C, CD  E, does A  E? Let us compute {A} + {A} + = {A, B, C} Therefore A  E is false

Murali Mani Decomposing Relations sNumbersNamepNumberpName s1Davep1MM s2Gregp2MM StudentProf FDs: pNumber  pName sNumbersNamepNumber s1Davep1 s2Gregp2 Student pNumberpName p1MM p2MM Professor

Murali Mani Decomposition: Lossless Join Property Generating spurious tuples sNumbersNamepName S1DaveMM S2GregMM Student pNumberpName p1MM p2MM Professor sNumbersNamepNumberpName s1Davep1MM s1Davep2MM s2Gregp1MM s2Gregp2MM StudentProf

Murali Mani Normalization Step Consider relation R with set of attributes A R. Consider a FD A  B (such that no other attribute in (A R – A – B) is functionally determined by A). If A is not a superkey for R, we may decompose R as: Create R’ (A R – B) Create R’’ with attributes A  B Key for R’’ = A

Murali Mani Normal Forms: BCNF Boyce Codd Normal Form (BCNF): For every non-trivial FD X  a in R, X is a superkey of R.

Murali Mani BCNF example SCI (student, course, instructor) FDs: student, course  instructor instructor  course Decomposition: SI (student, instructor) Instructor (instructor, course)

Murali Mani Dependency Preservation We might want to ensure that all specified FDs are captured. BCNF does not necessarily preserve FDs. 2NF, 3NF preserve FDs. studentinstructor DaveMM DaveER SI instructorcourse MMDB 1 ERDB 1 Instructor studentinstructorcourse DaveMMDB 1 DaveERDB 1 SCI (from SI and Instructor) SCI violates the FD student, course  instructor

Murali Mani Normal Forms: 3NF Third Normal Form (3NF): For every non- trivial FD X  a in R, either a is a prime attribute or X is a superkey of R.

Murali Mani 3NF - example Lot (propNo, county, lotNum, area, price, taxRate) Candidate key: FDs: county  taxRate area  price Decomposition: Lot (propNo, county, lotNum, area, price) County (county, taxRate)

Murali Mani 3NF - example Lot (propNo, county, lotNum, area, price) County (county, taxRate) Candidate key for Lot: FDs: county  taxRate area  price Decomposition: Lot (propNo, county, lotNum, area) County (county, taxRate) Area (area, price)

Murali Mani Extreme Example Consider relation R (A, B, C, D) with primary key (A, B, C), and FDs B  D, and C  D. R violates 3NF. Decomposing it, we get 3 relations as: R1 (A, B, C), R2 (B, D), R3 (C, D) Let us consider an instance where we need these 3 relations and how we do a natural join ⋈ ABC a1b1c1 a2b2c1 a3b1c2 BD b1d1 b2d2 R1 R2 CD c1d1 c2d2 R3 ABCD a1b1c1d1 a2b2c1d2 a3b1c2d1 R1 ⋈ R2: violates C  D ABCD a1b1c1d1 R1 ⋈ R2 ⋈ R3: no FD is violated

Murali Mani Define Foreign Keys? Consider the normalization step: A relation R with set of attributes A R, and a FD A  B, and A is not a key for R, we decompose R as: Create R’ (A R – B) Create R’’ with attributes A  B Key for R’’ = A We can also define foreign key R’ (A) references R’’ (A) Question: What is key for R’?

Murali Mani How does Normalization Help? Employee (ssn, name, lot, dept) Dept (did, dName) FK: Employee (dept) REFERENCES Dept (did) Suppose: employees of a dept are in the same lot FD: dept  lot Decomposing: Employee (ssn, name, dept) Dept (did, dName) DeptLot (dept, lot) (or) Employee (ssn, name, dept) Dept (did, dName, lot)