7 Copyright © 2006, Oracle. All rights reserved. Normalization of Relational Tables (Part II)

Slides:



Advertisements
Similar presentations
Chapter 5 Normalization of Database Tables
Advertisements

Chapter 5 Normalization of Database Tables
1 Week 4: Normalisation: Redundant data becomes inconsistent data; therefore … “The key, the whole key, and nothing but the key,so help me, Codd”
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 =
The Relational Model System Development Life Cycle Normalisation
Database Normalization MIS 520 – Database Theory Fall 2001 (Day) Lecture 4/5/6.
Chapter 8 Normalization. © 2001 The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Outline Modification anomalies Functional dependencies.
Normalization of Database Tables
Fundamentals, Design, and Implementation, 9/e Chapter 4 The Relational Model and Normalization.
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Developing Data Models for Business Databases.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 7 Normalization of Relational Tables.
Normalization of Database Tables
Normalization of Database Tables
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 5 The Relational Model and Normalization.
7-1 Normalization - Outline  Modification anomalies  Functional dependencies  Major normal forms  Practical concerns.
Chapter 5 Normalization of Database Tables
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
CS 3630 Database Design and Implementation. First Normal Form (1NF) No multi-value attributes Done when mapping E-R model to relational schema DBDL 2.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 5 Normalization of Database Tables.
Chapter 6 Developing Data Models for Business Databases.
NORMALIZATION N. HARIKA (CSC).
Database Normalization. This is the process which allows you to winnow out redundant data within your database. This involves restructuring the tables.
Normalization II. Boyce–Codd Normal Form (BCNF) Based on functional dependencies that take into account all candidate keys in a relation, however BCNF.
Normalization Quiz Tao Li Grant Horntvedt. 1. Which of the following statements is true: a. Normal forms can be derived by inspecting the data in various.
Introduction to Databases
Chapter 3 The Relational Model and Normalization
7 Copyright © 2006, Oracle. All rights reserved. Normalization of Relational Tables (Part I)
Chapter 5 Normalization of Database Tables
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall 9.1.
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Chapter 6 Normalization 正規化. 6-2 In This Chapter You Will Learn:  更動異常  How tables that contain redundant data can suffer from update anomalies ( 更動異常.
Fundamentals, Design, and Implementation, 9/e. Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 4/2 Copyright.
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Normalization A technique that organizes data attributes (or fields) such that they are grouped to form stable, flexible and adaptive entities.
Database Systems: Design, Implementation, and Management Tenth Edition
5 1 Chapter 5 Normalization of Database Tables Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Database Systems: Design, Implementation, and Management Ninth Edition Chapter 6 Normalization of Database Tables.
1 DATABASE SYSTEMS DESIGN IMPLEMENTATION AND MANAGEMENT INTERNATIONAL EDITION ROB CORONEL CROCKETT Chapter 7 Normalisation.
Chapter 7 Normalization. Outline Modification anomalies Functional dependencies Major normal forms Relationship independence Practical concerns.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
Concepts of Relational Databases. Fundamental Concepts Relational data model – A data model representing data in the form of tables Relations – A 2-dimensional.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 5 Normalization of Database.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Chapter 7 Normalization. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Modification anomalies Functional dependencies.
Data Normalization Normal is not something to aspire to, it's something to get away from. ~ Jodie Foster ~
10/3/2012ISC329 Isabelle Bichindaritz1 Logical Design.
Chapter 2 The Relational Data Model. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Relational model basics Integrity.
Chapters 15 &16 Conceptual and Logical Database Design Methodology.
1 5 Normalization. 2 5 Database Design Give some body of data to be represented in a database, how do we decide on a suitable logical structure for that.
Database Design, Application Development, and Administration, 5 th Edition Copyright © 2011 by Michael V. Mannino All rights reserved. Chapter 6 Developing.
CSE314 Database Systems Basics of Functional Dependencies and Normalization for Relational Databases Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E.
CIS 210 Systems Analysis and Development Week 6 Part II Designing Databases,
Lecture No 14 Functional Dependencies & Normalization ( III ) Mar 04 th 2011 Database Systems.
1 Functional Dependencies and Normalization Chapter 15.
Database Principles: Fundamentals of Design, Implementation, and Management Ninth Edition Chapter 6 Normalization of Database Tables Carlos Coronel, Steven.
Normalization of Database Tables
©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach.
In this session, you will learn to: Describe data redundancy Describe the first, second, and third normal forms Describe the Boyce-Codd Normal Form Appreciate.
Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 4/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Database Systems, 8 th Edition Improving the Design Table structures cleaned up to eliminate initial partial and transitive dependencies Normalization.
Normalisation 1NF to 3NF Ashima Wadhwa. In This Lecture Normalisation to 3NF Data redundancy Functional dependencies Normal forms First, Second, and Third.
Lecture 4: Logical Database Design and the Relational Model 1.
Logical Design 12/10/2009GAK1. Learning Objectives How to remove features from a local conceptual model that are not compatible with the relational model.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
Logical Database Design and Relational Data Model Muhammad Nasir
5 1 Chapter 5 Normalization of Database Tables Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Normalizing Database Designs. 2 Objectives In this chapter, students will learn: –What normalization is and what role it plays in the database design.
Chapter 2 The Relational Data Model. Outline Relational model basics Integrity rules Rules about referenced rows Relational Algebra.
* 07/16/96 Normalization 2/16/2019 *.
Presentation transcript:

7 Copyright © 2006, Oracle. All rights reserved. Normalization of Relational Tables (Part II)

BCNF A table is in BCNF if every determinant is a candidate key. –A stronger definition than 3NF –It is simpler because it does not refer to 2NF –It is better and covers a special case omitted by the original 3NF definition. Special cases not covered by 3NF –A part of a compound key  A part of a compound key –A nonkey column  A part of a compound key (The determinant of both FDs is not a candidate key) The first special case is only possible if there are multiple composite, candidate keys (The cases are not common).

Second and Third Normal Form (2NF and 3NF) A table is in 2NF if no partial dependency exists –Partial Dependency ( 部分的依賴 ) A part of a compound key → A nonkey column A table is in 3NF if it is in 2NF and no transitive dependency exists –Transitive Dependency ( 傳遞 / 遞移的依賴 ) A nonkey column  A nonkey column  

BCNF Example Primary key: ( StdSSN, OfferNo ) Violations of 2NF, 3NF, BCNF (2NF > 3NF > BCNF) –2NF (no partial dependency exists) : FD1, FD2 –3NF (in 2NF and no transitive dependency) : FD1, FD2, FD3 –BCNF (every determinant is a candidate key) : FD1, FD2, FD3 Split into four tables StdSSN, OfferNo  EnrGrade StdSSN  StdCity, StdClass (violation of 2NF, hence 3NF) OfferNo  OffTerm, OffYear, CourseNo (violation of 2NF, hence 3NF) CourseNo  CrsDesc (violation of 3NF, BCNF) FD 1 FD 2 FD 3 FD 4

Violation Example of BCNF UnivTable4 StdSSNOfferNo EnrGrade UnivTable4 is in 3NF, but not in BCNF. UnivTable4 is in 3NF because the only nonkey column ( EnrGrade ) depends on candidate keys (not on other nonkey column) in the FD diagram above. In UnivTable4, the dependencies between StdSSN and violate BCNF (every determinant is a candidate key). –Both StdSSN and are determants, but neither is an entire candidate key although each is a part of a candidate key. key columnnonkey column

Example of Handling BCNF Violation UnivTable4 StdSSNOfferNo EnrGrade UnivTable4-1 (StdSSN, ) UNIQUE ( ) UnivTable4-2 (StdSSN, OfferNo, EnrGrade) FOREIGN KEY (StdSSN) REFERENCES UnivTable4-1 UnivTable4 is in 3NF, but not in BCNF. (A table is in BCNF if every determinant is a whole candidate key.) key columnnonkey column PK of another table ( FK )

Violation Example of BCNF UnivTable5 is in 3NF (nonkey column depends on candidate key) – Status is the only nonkey column. – Status depends on the entire candidate keys ( or ) UnivTable5 is not in BCNF (every determinant is a candidate key). –The dependency diagram shows that AdvisorNo is a determinant (for Major) but not a candidate key. UnivTable5 is in 3NF, but not in BCNF. UnivTable5 AdvisorNoStdSSNMajorStatus A1S1ISCOMPLETED A2S1FINPENDING A1S2ISPENDING A3S2FINCOMPLETED key columnnonkey column

Example of Handling BCNF Violation UnivTable5-1 (AdvisorNo, Major) UnivTable5-2 (AdvisorNo, StdSSN, Status) FOREIGN KEY (AdvisorNo) REFERENCES UnivTable5-1 UnivTable5 is in 3NF, but not in BCNF. UnivTable5 AdvisorNoStdSSNMajorStatus A1S1ISCOMPLETED A2S1FINPENDING A1S2ISPENDING A3S2FINCOMPLETED PK PK of another table ( FK ) key columnnonkey column

Simple Synthesis ( 合成 ) Procedure (For Generating Tables Satisfying BCNF) Starting point Starting with a list of simple functional dependencies Synthesis –Individual simple FDs are combined into composite FDs –Composite FDs are used to construct tables 5 steps in total –First 2 steps eliminate redundancy by removing extraneous ( 無關的 ) columns and derived FDs. –Last 3 steps produce tables by using composite FDs.

Simple Synthesis ( 合成 ) Procedure 1.Eliminate extraneous ( 無關的 ) columns from the LHS of FDs 2.Remove derived FDs (Transitive Dependency) 3.Arrange the simple FDs of same LHS into groups (composite FDs) with each group having the same LHS. 4.Make a table for each composite FD group with its determinant as the primary key. 5.Merge two similar tables into one table if one of the two tables contains all columns of the other one. –Choose a PK from one of the two tables as the PK of the merged table –Define the unique constraints for the PK column of the other table, that is not designated as the PK of the merged table 6.Add foreign keys

Simple Synthesis Example I Step 1: Eliminate extraneous columns from the LHS of FDs Check if the LHS of any FD contains two or more columns. Check if any column of the candidate LHSs is the RHS of any FD. StdSSN, StdClass  StdCity StdSSN  StdClass StdSSN   StdSSN OfferNo  OffTerm OfferNo  OffYear OfferNo  CourseNo OfferNo  CrsDesc CourseNo  CrsDesc StdSSN, OfferNo  EnrGrade StdSSN  StdCity StdSSN  StdClass StdSSN   StdSSN OfferNo  OffTerm OfferNo  OffYear OfferNo  CourseNo OfferNo  CrsDesc CourseNo  CrsDesc StdSSN, OfferNo  EnrGrade Is StdSSN or OfferNo at the RHS of any FD ?

Simple Synthesis Example I Step 2: Eliminate transitive dependency (derived FDs ) StdSSN  StdCity StdSSN  StdClass StdSSN   StdSSN OfferNo  OffTerm OfferNo  OffYear OfferNo  CourseNo OfferNo  CrsDesc CourseNo  CrsDesc StdSSN, OfferNo  EnrGrade StdSSN  StdCity StdSSN  StdClass StdSSN   StdSSN OfferNo  OffTerm OfferNo  OffYear OfferNo  CourseNo CourseNo  CrsDesc StdSSN, OfferNo  EnrGrade OfferNo  CrsDesc is an transitive dependency.

Simple Synthesis Example I Step 3: Arrange simple FDs of same LHS into a composite FD StdSSN  StdCity StdSSN  StdClass StdSSN   StdSSN OfferNo  OffTerm OfferNo  OffYear OfferNo  CourseNo CourseNo  CrsDesc StdSSN, OfferNo  EnrGrade StdSSN  StdCity, StdClass,  StdSSN OfferNo  OffTerm, OffYear, CourseNo CourseNo  CrsDesc StdSSN, OfferNo  EnrGrade

Simple Synthesis Example I Step 4: Make a table for each FD group with the determinant as the primary key. Result: Five tables Student, Student2, Offering, Course, Enrollment Student (StdSSN, StdCity, StdClass, ) Student2 ( , StdSSN) Offering (OfferNo, OffTerm, OffYear, CourseNo) Course (CourseNo, CrsDesc) Enrollment (StdSSN, OfferNo, EnrGrade) StdSSN  StdCity, StdClass,  StdSSN OfferNo  OffTerm, OffYear, CourseNo CourseNo  CrsDesc StdSSN, OfferNo  EnrGrade

Simple Synthesis Example I Step 5: Merge tables Merge two similar tables into one table if one of the two tables contains all columns of the other one. Student (StdSSN, StdCity, StdClass, ) Student2 ( , StdSSN) Offering (OfferNo, OffTerm, OffYear, CourseNo) Course (CourseNo, CrsDesc) Enrollment (StdSSN, OfferNo, EnrGrade) Student (StdSSN, StdCity, StdClass, ) UNIQUE ( ) Offering (OfferNo, OffTerm, OffYear, CourseNo) Course (CourseNo, CrsDesc) Enrollment (StdSSN, OfferNo, EnrGrade)

Add Foreign Keys Student (StdSSN, StdCity, StdClass, ) UNIQUE ( ) Offering (OfferNo, OffTerm, OffYear, CourseNo) FOREIGN KEY (CourseNo) REFERENCES Course Course (CourseNo, CrsDesc) Enrollment (StdSSN, OfferNo, EnrGrade) FOREIGN KEY (StdSSN) REFERENCES Student FOREIGN KEY (OfferNo) REFERENCES Offering

Multiple Candidate Keys A common misconception by novice database developers is that a table with multiple candidate keys violate BCNF. Multiple candidate keys do not violate either 3NF or BCNF necessarily. Step 5 of the Simple Synthesis Procedure creates tables with multiple candidate keys. You should not split a table just because it contains multiple candidate keys. Splitting a table unnecessarily can slow query performance.

Simple Synthesis Example II Reviews of Paper ( 論文的審查 ) Author ( 作者 ) information includes the unique author number, the name, the mailing address, and the unique but optional address. Paper ( 論文 ) information includes the primary author, the unique paper number, the title, the abstract, and the review status (pending, accepted, rejected). Reviewer ( 審查者 ) information includes the unique reviewer number, the name, the mailing address, and a unique but optional address. A completed review includes the reviewer number, the date, the paper number, comments to the authors, comments to the program chairman, and rating (overall, originality, correctness, style, and relevance). The combination of reviewer number and paper number identifies a review.

Simple Synthesis Example II AuthNo  AuthName, Auth , AuthAddress Auth  AuthNo PaperNo  Primary_AuthNo, Title, Abstract, Status RevNo  RevName, Rev , RevAddress Rev  RevNo RevNo, PaperNo  Auth_Comm, Prog_Comm, Date, Rating1, Rating2, Rating3, Rating4, Rating5 The steps of simple synthesis The first step is finished because the LHS is minimal in each FD. The second step is not necessary because there are no transitive dependency. The third step is finished because the FDs are in groups. The fourth step : define a table for each of the six FD groups The fifth step : merge similar tables and add foreign keys

Simple Synthesis Example II Solution Author(AuthNo, AuthName, Auth , AuthAddress) UNIQUE (Auth ) Paper(PaperNo, Primary_Auth, Title, Abstract, Status) FOREIGN KEY (Primary_Auth) REFERENCES Author Reviewer(RevNo, RevName, Rev , RevAddress) UNIQUE (Rev ) Review(PaperNo, RevNo, Auth_Comm, Prog_Comm, Date, Rating1, Rating2, Rating3, Rating4, Rating5) FOREIGN KEY (PaperNo) REFERENCES Paper FOREIGN KEY (RevNo) REFERENCES Reviewer

Practical Concerns: Role of Normalization Two ways to use normalization in DB development process As a refinement ( 精鍊 ) tool –Use after the ERD is converted into tables –Apply to each table As an initial design tool –Use normalization instead of ERD drawing in data modeling –Identify attributes and their functional dependencies –Apply normalization to generate tables –Add referential integrity constraints

Advantages of Refinement Approach Easier to translate requirements into an ERD than into a list of FDs During ERD development, related fields are grouped intuitively. Much normalization is done in an informal manner. There are fewer FDs to specify and less normalization to perform. Relationships can be overlooked when using normalization as the initial design approach

Normalization Objective Normalization results in a DB design with many tables to avoid modification anomalies Many tables  Easier to change, but  Difficult to query Normalization is update-biased If a database is used predominantly for queries, avoiding modification anomalies may not be an appropriate design goal.

Denormalization (反正規劃) A process of combing tables so that they are easier to query. Purposeful violation of normal forms –Most FDs will lead to anomalies if ignored. May improve performance

Summary Beware of unwanted redundancies FDs are important constraints Use a CASE tool for large problems Important tool of database development Focus on the normalization objective 自我練習 第七章 242 頁 13, 14, 15, 16