Logical Database Design ( 補 ) Unit 7 Logical Database Design ( 補 )

Slides:



Advertisements
Similar presentations
Unit 5 The Network Model  5.1 The Network Model  5.2 IDMS.
Advertisements

Normalization: Kroenke Chapters 3 and 4. A relation is categorized by one of several normal forms. An aid to design helps characterize relations that.
 Definition  Components  Advantages  Limitations Contents  Definition Definition  Normal Forms Normal Forms  First Normal Form First Normal Form.
Wei-Pang Yang, Information Management, NDHU More on Normalization Unit 18 More on Normalization ( 表格正規化探討 ) 18-1.
Normalisation The theory of Relational Database Design.
Ch 10, Functional Dependencies and Normal forms
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.
Design Guidelines Normalisation Table Design. Informal Design Guidelines Table Semantics A table should hold information about one and only one entity/concept.
Part 6 Chapter 15 Normalization of Relational Database Csci455 r 1.
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
Bad DB Design Duplicate of data Duplicate of data Updating Updating Deleting Deleting.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Week 6 Lecture Normalization
Data Manipulation 11 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and other programming.
6.8 Case Study: E-R for Supplier-and-Parts Database
7-1 Unit 4 Relational Database Design 英文版: Chap 7 “Relational Database Design” 中文版:第 6 章 “ 關聯式資料庫設計 ”
Logical Database Design Unit 7 Logical Database Design.
Dr. T. Y. Lin | SJSU | CS 157A | Fall 2015 Chapter 3 Database Normalization 1.
3-1 Unit 3 The Relational Model. 3-2 Wei-Pang Yang, Information Management, NDHU Outline  3.1 Introduction  3.2 Relational Data Structure  3.3 Relational.
3-1 Unit 3 The Relational Model. 3-2 Wei-Pang Yang, Information Management, NDHU Outline  3.1 Introduction  3.2 Relational Data Structure  3.3 Relational.
Wei-Pang Yang, Information Management, NDHU Normalization Unit 7 Normalization ( 表格正規化 ) 7-1.
NormalizationNormalization Chapter 4. Purpose of Normalization Normalization  A technique for producing a set of relations with desirable properties,
Database Design (Normalizations) DCO11310 Database Systems and Design By Rose Chang.
Further Normalization II: Higher Normal Forms Prof. Yin-Fu Huang CSIE, NYUST Chapter 13.
Schema Refinement and Normal Forms 20131CS3754 Class Notes #7, John Shieh.
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
Data Integrity An empty database is a correct database.
FEN Quality checking table design: Design Guidelines Normalisation Table Design Is this OK?
Functional Dependencies and Normalization for Relational Databases.
Further Normalization I
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.
CSE314 Database Systems Basics of Functional Dependencies and Normalization for Relational Databases Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E.
Lecture No 14 Functional Dependencies & Normalization ( III ) Mar 04 th 2011 Database Systems.
Data Manipulation 21 After this lecture, you should be able to:  Use SQL SELECT statement effectively to retrieve the data from multiple related tables.
Unit 5 The Network Model  5.1 Data Modeling Issues  5.2 The Network Model  5.3 IDMS.
1 Functional Dependencies and Normalization Chapter 15.
IST 210 Normalization 2 Todd Bacastow IST 210. Normalization Methods Inspection Closure Functional dependencies are key.
©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.
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.
Perform DFS from A A B C D E F G. Perform BFS from A A B C D E F G.
CS 338Database Design and Normal Forms9-1 Database Design and Normal Forms Lecture Topics Measuring the quality of a schema Schema design with normalization.
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
Dr. T. Y. Lin | SJSU | CS 157A | Fall 2015 Chapter 3 Database Normalization 1.
Al-Imam University Girls Education Center Collage of Computer Science 1 st Semester, 1432/1433H Chapter 10_part 1 Functional Dependencies and Normalization.
Views Prof. Yin-Fu Huang CSIE, NYUST Chapter 10. Advanced Database System Yin-Fu Huang 10.1Introduction Example: Var Good_Supplier View (S Where Status.
Objectives of Normalization  To create a formal framework for analyzing relation schemas based on their keys and on the functional dependencies among.
Advanced Database System
NORMALIZATION Handout - 4 DBMS. What is Normalization? The process of grouping data elements into tables in a way that simplifies retrieval, reduces data.
Relational Data Model, Review Relation Tuple Attribute Domains Candidate key, primary key Key attribute, non-key attribute.
Lecture # 17 Chapter # 10 Normalization Database Systems.
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.
Dr. T. Y. Lin | SJSU | CS 157A | Fall 2015 Chapter 3 Database Normalization 1.
STRUCTURE OF PRESENTATION :
Normalization (Database Design)
Normalization Karolina muszyńska
A brief summary of database normalization
STRUCTURE OF PRESENTATION :
پايگاه داده ها.
Φροντιστήριο SQL (από το βιβλίο του Date)
Unit 7 Normalization (表格正規化).
Relational Database Design
Sampath Jayarathna Cal Poly Pomona
STRUCTURE OF PRESENTATION :
Question 1: Basic Concepts (45 %)
STRUCTURE OF PRESENTATION :
Presentation transcript:

Logical Database Design ( 補 ) Unit 7 Logical Database Design ( 補 )

Wei-Pang Yang, Information Management, NDHU 7-2 Contents  7.1 Introduction  7.2 Functional Dependency  7.3 Normal Forms  First (1NF)  Second (2NF)  Third (3NF)

Introduction  Logical Database Design vs. Physical Database Design  Problem of Normalization  Normal Forms

Wei-Pang Yang, Information Management, NDHU 7-4 Logical Database Design  Logical Database Design vs. Physical Database Design Logical Database Design: How to organize relations/ tables? Physical Database Design: How to store data in disk storage?  Logical Database Design Normalization Semantic Modeling/ ER Model/ …  Problem of Normalization/ Logical Database Design Given some body of data to be represented in a database, how to decide the suitable logical structure they should have? what relations should exist? what attributes should they have?

Wei-Pang Yang, Information Management, NDHU 7-5 Problem of Normalization S1, Smith, 20, London, P1, Nut, Red, 12, London, 300 S1, Smith, 20, London, P2, Bolt, Green, 17, Paris, 200. S4, Clark, 20, London, P5, Cam, Blue, 12, Paris, 400 Normalization S S# SNAME STATUS CITY s1.. London.. P SP P# S# P# QTY... S' S# SNAME STATUS S1 Smith. S P SP' P# S# CITY P# QTY S1 London P1 300 S1 London P ( 異常 ) Redundancy Update Anomalies! or

Wei-Pang Yang, Information Management, NDHU 7-6 Normal Forms  A relation is said to be in a particular normal form if it satisfies a certain set of constraints. 1NF: A relation is in First Normal Form (1NF) iff it contains only atomic values. universe of relations (normalized and un-normalized) 1NF relations (normalized relations) 2NF relations 3NF relations 4NF relations BCNF relations 5NF relations Fig. 7.1: Normal Forms

Functional Dependency  Functional Dependency (FD)  Fully Functional Dependency (FFD)

Wei-Pang Yang, Information Management, NDHU 7-8 Functional Dependency  Functional Dependency Def: Given a relation R, R.Y is functionally dependent on R.X iff each X-value has associated with it precisely one Y-value (at any time). Note: X, Y may be the composite attributes.  Notation: R.X R.Y read as "R.X functionally determines R.Y" R X Y

Wei-Pang Yang, Information Management, NDHU 7-9 Functional Dependency (cont.) S S.S# S.SNAME S.S# S.STATUS S.S# S.CITY S.STATUS S.CITY FD Diagram: S# SNAME CITY STATUS S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens S Note: Assume STATUS is some factor of Supplier and no any relationship with CITY.

Wei-Pang Yang, Information Management, NDHU 7-10 Functional Dependency (cont.) P SP P# PNAME CITY COLOR WEIGHT S# P# QTY  If X is a candidate key of R, then all attributes Y of R are functionally dependent on X. (i.e. X Y) P# PNAME COLOR WEIGHT CITY P1 Nut Red 12 London P2 Bolt Green 17 Paris P3 Screw Blue 17 Rome P4 Screw Red 14 London P5 Cam Blue 12 Paris P6 Cog Red 19 London P S# P# QTY S1 P1 300 S1 P2 200 S1 P3 400 S1 P4 200 S1 P5 100 S1 P6 100 S2 P1 300 S2 P2 400 S3 P2 200 S4 P2 200 S4 P4 300 S4 P5 400 SP

Wei-Pang Yang, Information Management, NDHU 7-11 Functional Dependency (cont.) 1. FD is a semantic notion. S# CITY Means: each supplier is located in precisely one city. 2. FD is a special kind of integrity constraint. CREATE INTEGRITY RULE SCFD CHECK FORALL SX FORALL SY (IF SX.S# = SY.S# THEN SX.CITY = SY.CITY); 3. FDs considered here applied within a single relation. SP.S# S.S# is not considered!

First, Second, and Third Normal Forms (1NF, 2NF, 3NF)

Wei-Pang Yang, Information Management, NDHU 7-13 Normal Forms: 1NF  Def: A relation is in 1NF iff all underlying simple domains contain atomic values only. S# STATUS CITY (P#, QTY) S1 20 London {(P1, 300), (P2, 200),..., (P6, 100)} S2 10 Paris {(P1, 300), (P2, 400)} S3 10 Paris {(P2, 200)} S4 20 London {(P2, 200), (P4, 300), (P5, 400)} S # STATUS CITY P# QTY S1 20 London P1 300 S1 20 London P2 200 S1 20 London P3 400 S1 20 London P4 200 S1 20 London P5 100 S1 20 London P6 100 S2 10 Paris P1 300 S2 10 Paris P2 400 S3 10 Paris P2 200 S4 20 London P2 200 S4 20 London P4 300 S4 20 London P5 400 Key:(S#,P#), Normalized 1NF FIRST Suppose 1. CITY is the main office of the supplier. 2. STATUS is some factor of CITY

Wei-Pang Yang, Information Management, NDHU NF Problem: Update Anomalies! Update If suppler S1 moves from London to Paris, then 6 tuples must be updated! Insertion Cannot insert a supplier information if it doesn't supply any part, because that will cause a null key value. Deletion Delete the information that "S3 supplies P2", then the fact "S3 is located in Paris" is also deleted. S# STATUS CITY P# QTY..... S3 20 Paris P S5 30 Athens NULL NULL FIRST S # STATUS CITY P# QTY S1 20 London P1 300 S1 20 London P2 200 S1 20 London P3 400 S1 20 London P4 200 S1 20 London P5 100 S1 20 London P6 100 S2 10 Paris P1 300 S2 10 Paris P2 400 S3 10 Paris P2 200 S4 20 London P2 200 S4 20 London P4 300 S4 20 London P5 400 Key:(S#,P#), Normalized 1NF FIRST

Wei-Pang Yang, Information Management, NDHU NF Problem: Update Anomalies! (cont.) Suppose 1. CITY is the main office of the supplier. 2. STATUS is some factor of CITY Primary key of FIRST: (S#, P#) FD diagram of FIRST: S# P# CITY STATUS QTY FF D x FD FD FD: 1. S# STATUS 2. S# CITY 3. CITY STATUS 4. (S#, P#) QTY FD primary key (S#, P#) STATUS primary key (S#, P#) CITY S # STATUS CITY P# QTY S1 20 London P1 300 S1 20 London P2 200 S1 20 London P3 400 S1 20 London P4 200 S1 20 London P5 100 S1 20 London P6 100 S2 10 Paris P1 300 S2 10 Paris P2 400 S3 10 Paris P2 200 S4 20 London P2 200 S4 20 London P4 300 S4 20 London P5 400 Key:(S#,P#), Normalized 1NF FIRST

Wei-Pang Yang, Information Management, NDHU 7-16 Normal Form: 2NF  Def: A relation R is in 2NF iff (1) R is in 1NF (i.e. atomic ) (2) Non-key attributes are FD on primary key. (e.g. QTY, STATUS, CITY in FIRST) FIRST is in 1NF, but not in 2NF (S#, P#) STATUS, and (S#, P#) CITY FD Decompose FIRST into: SECOND (S#, STATUS, CITY): primary key: S# S# CITY STATUS FD: 1. S# STATUS 2. S# CITY 3. CITY STATUS S# P# CITY STATUS QTY FFD x FD FD SP (S#, P#, QTY): P rimary key: (S#, p#) S# P# QTY FD: 4. (S#, P#) QTY

Wei-Pang Yang, Information Management, NDHU 7-17 Normal Form: 2NF (cont.) S# STATUS CITY S1 20 London S2 10 Paris S3 10 Paris S4 20 London S5 30 Athens SECOND (in 2NF) S# P# QTY) S1 P1 300 S1 P2 200 S1 P3 400 S1 P4 200 S1 P5 100 S2 P1 300 S2 P2 400 S3 P2 200 S4 P4 300 S4 P5 400 SP (in 2NF) S # STATUS CITY P# QTY S1 20 London P1 300 S1 20 London P2 200 S1 20 London P3 400 S1 20 London P4 200 S1 20 London P5 100 S1 20 London P6 100 S2 10 Paris P1 300 S2 10 Paris P2 400 S3 10 Paris P2 200 S4 20 London P2 200 S4 20 London P4 300 S4 20 London P5 400 FIRST Update: S1 moves from London to Paris Insertion: (S5 30 Athens) Deletion Delete "S3 supplies P2 200", then the fact "S3 is located in Paris" is also deleted.

Wei-Pang Yang, Information Management, NDHU 7-18 Normal Form: 2NF (cont.)  A relation in 1NF can always be reduced to an equivalent collection of 2NF relations.  The reduction process from 1NF to 2NF is non-loss decomposition. FIRST(S#, STATUS, SCITY, P#, QTY) projections natural joins SECOND(S#, STATUS, CITY), SP(S#,P#,QTY)  The collection of 2NF relations may contain “more” information than the equivalent 1NF relation. (S5, 30, Athens) 2nd SP 1st

Wei-Pang Yang, Information Management, NDHU 7-19 Problem: Update Anomalies in SECOND! Update Anomalies in SECOND UPDATE: if the status of London is changed from 20 to 60, then two tuples must be updated DELETE: delete supplier S5, then the fact "the status of Athens is 30" is also deleted! INSERT: cannot insert the fact "the status of Rome is 50"! Why: S.S# S.STATUS S.S# S. CITY S.CITY S.STATUS cause a transitive dependency S# STATUS CITY S1 20 London S2 10 Paris S3 10 Paris S4 20 London S5 30 Athens SECOND (in 2NF) S# CITY STATUS FD: 1. S# STATUS 2. S# CITY 3. CITY STATUS

Wei-Pang Yang, Information Management, NDHU 7-20 Normal Forms: 3NF  Def : A relation R is in 3NF iff (1) R is in 2NF (2) Every non-key attribute is non-transitively dependent on the primary key. e.g. STATUS is transitively on S# (i.e., non-key attributes are mutually independent) SP is in 3NF, but SECOND is not! S# P# QTY SP FD diagram S# STATUS CITY S1 20 London S2 10 Paris S3 10 Paris S4 20 London S5 30 Athens SECOND (not 3NF) S# CITY STATUS SECOND FD diagram

Wei-Pang Yang, Information Management, NDHU 7-21 Normal Forms: 3NF (cont.)  Decompose SECOND into: SC(S#, CITY) primary key : S# FD diagram: CS(CITY, STATUS): primary key: CITY FD diagram: S# CITY STATUS S# CITY S1 London S2 Paris S3 Paris S4 London S5 Athens SC (in 3NF) CITY STATUS Athens 30 London 20 Paris 10 Rome 50 CS (in 3NF) S# STATUS CITY S1 20 London S2 10 Paris S3 10 Paris S4 20 London S5 30 Athens SECOND S# STATUS CITY

Wei-Pang Yang, Information Management, NDHU 7-22 Normal Forms: 3NF (cont.)  Note: (1) Any 2NF diagram can always be reduced to a collection of 3NF relations. (2) The reduction process from 2NF to 3NF is non-loss decomposition. (3) The collection of 3NF relations may contain "more information" than the equivalent 2NF relation.

Wei-Pang Yang, Information Management, NDHU 7-23 Good and Bad Decomposition  Consider S# CITY STATUS transitive FD S# CITY STATUS Good ! (Rome, 50) can be inserted. ① Decomposition A: SC: CS: S# CITY S# STATUS Bad ! (Rome, 50) can not be inserted unless there is a supplier located at Rome. ② Decomposition B: SC: CS: ③ Decomposition C: S# -> status city -> status ‘Good’ or ‘Bad’ is dependent on item’s semantic meaning!! S# STATUS CITY S# STATUS CITY Suppose 1. CITY is the main office of the supplier. 2. STATUS is some factor of CITY

Wei-Pang Yang, Information Management, NDHU 7-24 Why Normal Form?  Avoid update anomalies  Consider the SSP(S#, SNAME, P#, QTY) Common sense will tell us SS(S#, SNAME) & SP(S#, P#, QTY) is a better design.  The concepts of FD, 1NF, 2NF, 3NF and BCNF to formalize common sense.  Mechanization is possible! i.e., we can write a program to do the work of normalization for us!

Wei-Pang Yang, Information Management, NDHU 7-25 Concluding Remarks  The technique of non-loss decomposition is an aid to logical database design.  The overall processes of Normalization: step1: eliminate non-full dependencies. step2: eliminate any transitive FDs. step3: eliminate those FDs in which the determinant is not a candidate key.  General objective: reduce redundancy, and then avoid certain update anomalies.  Normalization Guidelines are only guidelines. Sometime there are good reasons for not normalizing all the way.

Wei-Pang Yang, Information Management, NDHU 7-26 Concluding Remarks (cont.) NADDR (NAME, STREET, CITY, STATE, ZIP) NAME STREET CITY STATE ZIP not in 5NF (in which NF?) decompose NSZ (NAME, STREET, ZIP) ZCS (ZIP, CITY, STATE) NAME STREET ZIP ZIP CITY STATE

Wei-Pang Yang, Information Management, NDHU 7-27 Concluding Remarks (cont.)  However, (1) STREET, CITY, STATE are almost required together. (2) so ZIP do not change very often, such a decomposition seems unlikely to be worthwhile.  Not all redundancies can be eliminate by projection.