BIS 360 – Lecture Eight Ch. 12: Database Design and Normalization.

Slides:



Advertisements
Similar presentations
Database Design: Normalization J.G. Zheng June 29 th 2005 DB Chapter 4.
Advertisements

Chapter 5 Normalization of Database Tables
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Normalization ISYS 464. Database Design Based on ERD Strong entity: Create a table that includes all simple attributes –Composite Weak entity: add owner.
Normalization Dr. Mario Guimaraes. Data Normalization Primarily a tool to validate and improve a logical design so that it satisfies certain constraints.
Ch 10, Functional Dependencies and Normal forms
1 Logical Database Design and the Relational Model Modern Database Management.
Modeling the Data: Conceptual and Logical Data Modeling
Data Modeling and Relational Database Design ISYS 650.
Systems Development Life Cycle
Accounting 6500 Relational Databases: Accounting Applications Introduction to Normalization.
© 2005 by Prentice Hall 1 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 7 th Edition Jeffrey A. Hoffer, Mary B.
© 2005 by Prentice Hall Chapter 3a Database Design Modern Systems Analysis and Design Fourth Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich.
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
The Relational Database Model:
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Normalization A337. A337 - Reed Smith2 Structure What is a database? ◦ Tables of information  Rows are referred to as records  Columns are referred.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Mapping ERM to relational database
Normalization Rules for Database Tables Northern Arizona University College of Business Administration.
Daniel AdinugrohoDatabase Programming 1 DATABASE PROGRAMMING Lecture on 29 – 04 – 2005.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall 9.1.
Chapter 4: Logical Database Design and the Relational Model (Part II)
Week 6 Lecture Normalization
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.
BIS 360 – Lecture Six (Part 2) Conceptual Data Modeling (Chapter 10 and partial Chapter 12)
Concepts and Terminology Introduction to Database.
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Avoiding Database Anomalies
© 2002 by Prentice Hall 1 Database Design David M. Kroenke Database Concepts 1e Chapter 5 5.
Normalization A technique that organizes data attributes (or fields) such that they are grouped to form stable, flexible and adaptive entities.
1 A Guide to MySQL 2 Database Design Fundamentals.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 5 Normalization of Database.
Logical Database Design Relational Model. Logical Database Design Logical database design: process of transforming conceptual data model into a logical.
SALINI SUDESH. Primarily a tool to validate and improve a logical design so that it satisfies certain constraints that avoid unnecessary duplication of.
Chapter 7 1 Database Principles Data Normalization Primarily a tool to validate and improve a logical design so that it satisfies certain constraints that.
10/3/2012ISC329 Isabelle Bichindaritz1 Logical Design.
Normalization Well structured relations and anomalies Normalization First normal form (1NF) Functional dependence Partial functional dependency Second.
Unit 4 Object Relational Modeling. Key Concepts Object-Relational Modeling outcomes and process Relational data model Normalization Anomalies Functional.
Lecture No 14 Functional Dependencies & Normalization ( III ) Mar 04 th 2011 Database Systems.
ITN Table Normalization1 ITN 170 MySQL Database Programming Lecture 3 :Database Analysis and Design (III) Normalization.
Database Design – Lecture 8
1 Functional Dependencies and Normalization Chapter 15.
CS263 Lecture 5: Logical Database Design Can express the structure of a relation by a Tuple, a shorthand notation Name of the relation is followed (in.
Chapter 10 Designing Databases. Objectives:  Define key database design terms.  Explain the role of database design in the IS development process. 
1 Class Agenda (04/06/2006 and 04/11/2006)  Discuss use of Visio for ERDs  Learn concepts and ERD notation for data generalization  Introduce concepts.
Logical Database Design and the Relational Model.
Bordoloi CMIS 450: Database Design Dr. Bijoy Bordoloi Transforming E/R Diagrams to Relations.
6-1 © Prentice Hall, 2007 Topic 6: Object-Relational Modeling Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
Chapter 8: Object-Relational Modeling Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey A. Hoffer.
8-1 © Prentice Hall, 2007 Chapter 8: Object-Relational Modeling Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
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.
NormalisationNormalisation Normalization is the technique of organizing data elements into records. Normalization is the technique of organizing data elements.
Normalization ACSC 425 Database Management Systems.
IMS 4212: Normalization 1 Dr. Lawrence West, Management Dept., University of Central Florida Normalization—Topics Functional Dependency.
Logical Database Design and Relational Data Model Muhammad Nasir
What Is Normalization  In relational database design, the process of organizing data to minimize redundancy  Usually involves dividing a database into.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
Normalization ISYS 464. Database Design Based on ERD Strong entity: Create a table that includes all simple attributes –Composite Weak entity: add owner.
SEEM3430: Information Systems Analysis and Design
Chapter 5: Logical Database Design and the Relational Model
MIS 322 – Enterprise Business Process Analysis
Payroll Management System
بسم الله الرحمن الرحيم.
Translation of ER-diagram into Relational Schema
Chapter 9 Designing Databases
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Database Normalization.
Presentation transcript:

BIS 360 – Lecture Eight Ch. 12: Database Design and Normalization

Objectives Where are we? ER Diagram Transformation Why DB Normalization? Database Anomalies Normalization Theory 1NF - 3NF

Where we are now Project ID and Selection Project Initiation & Planning Analysis Logical Design Physical Design Implementation Maintenance 1. Database Design (Ch. 12) 2. Form and Report Design (Ch. 13) 3. Interface Design (Ch. 14)

Why we design a database E-R ModelDFD Model  Information Database  Applications  Reports Bills Charts...

DB Design – Where we start From the Conceptual Data Model (ERD) examine the diagram for accuracy – entities, attributes,relationships, and cardinalities Transform this Conceptual Data Model into Logical Data Model (i.e., Relational Data Model) a set of flat tables (relations)

ER Diagram Transformation Step 1: For each regular entity type E, create a relation R that includes all the simple attributes. A unique identifier of E will be a primary key of R EMPLOYEE EmpIDEmpLNameEmpFNameSalary PK: EmpID E R

ER Diagram Transformation Step 2: For each weak entity type W with identifying entity type E, create a relation Rw with all the attributes of W and also create a relation Re for E as explained in Step 1. Then, include the primary key of Re as a foreign key of Rw. A combination of the partial identifier of W and the unique identifier of E will be a primary key of Rw. EMPLOYEE EmpIDEmpLNameEmpFNameSalary PK: EmpID DEPENDENT EW DpdSSNDpdLNameDpdFNameEmpID PK: EmpID + DpdSSN FK: EmpID Re Rw

ER Diagram Transformation Step 3: When there is a 1:1 relationship between entity type S and T, create relations Rs and Rt as explained in step 1. Include a primary key of S as a foreign key of T. EMPLOYEE EmpIDEmpLNameEmpFNameSalary PK: EmpID DEPARTMENT ST DeptIDDeptNameDeptPhoneEmpID PK: DeptID FK: EmpID Rs Rt manages is managed by

ER Diagram Transformation Step 4: When there is a 1:M relationship between entity types S and T, create relations Rs and Rt as explained in step 1. If T is an entity type at the MANY-side, include a primary key of Rs as a foreign key of Rt. DEPARTMENT DeptIDDeptNameDeptPhone PK: DeptID EMPLOYEE ST EmpIDEmpLNameEmpFNameSalaryDeptID PK: EmpID FK: DeptID Rs Rt works for hires

ER Diagram Transformation Step 5: When there is a M:N relationship P between entity types S and T and there is no property associated with this relationship P, create relations Rs and Rt as explained in step 1. Also create a relation Rp to represent the relationship and include primary keys of Rs and Rt as foreign keys of Rp. A combination of primary keys of Rs and Rt will be a primary key of Rp. WhIDWhName PK: WhID WAREHOUSEPRODUCT ST WhIDProdID PK: WhID + ProdID FK: WhID, ProdID Rs Rp ProdIDProdNameProdPrice Rt PK: ProdID

ER Diagram Transformation Step 6: When there is a M:N relationship P between entity types S and T and there are some properties associated with this relationship P, create relations Rs, Rt, and Rp as explained in step 5. All properties associated with the relationship P will be the non-key attributes of Rp. SchID STUDENT SCHOOL SSN Name Phone ZIP Name Type ZIP Attends Date STUDENT ( SSN, Name, Phone, Zip ) SCHOOL ( SchID, Name, Type, Zip ) STU_SCH ( SSN, SchID, Date, Degree ) Degree

Complex ERD Transformation Example of (M:N) Relationship ORDER ( CID, ProdID, Date, Units ) Same customer may order same product many times Q: Are you happy with the above design? ProdID CUSTOMER PRODUCT CID Name Phone ZIP Desc. U_Price Qty Order Date Units

Complex ERD Transformation Example of (M:N) Relationship ORDER ( OrderID, CID, ProdID, Date, Units ) Same customer may order same product many times ProdID CUSTOMER PRODUCT CID Name Phone ZIP Desc. U_Price Qty Order Date Units Create a unique primary key – OrderID

Why DB Normalization? To avoid database processing errors (anomalies) To verify the relations derived from the ER diagram – each derived relation would be at least in 3rd normal form (3NF)

Database Anomalies Anomalies -- Data errors occurred during or after the processing of data Three types of anomalies Insertion anomaly - the difficulty in adding new data due to the poor design of a relation Deletion Anomaly - unintentional data loss due to the deletion of some data Update Anomaly - data become inconsistent after some data were updated

Insertion Anomaly EmpIDDeptNameProjectBudgetLocation 1MktJohnA100000MI 1MktJohnB200000IN 2EngJimA100000MI 3AcctJoeC350000IL EMPLOYEE-PROJECT EmpIDDeptNameProjectBudgetLocation 1MktJohnA100000MI 1MktJohnB200000IN 2EngJimA100000MI 3AcctJoeC350000IL 4FinJackA100000MI 4FinJackC350000IL 5HRJunenull !!null Insert new employees

Insertion Anomaly EmpIDDeptNameProjectBudgetLocation 1MktJohnA100000MI 1MktJohnB200000IN 2EngJimA100000MI 3AcctJoeC350000IL EMPLOYEE-PROJECT EmpIDDeptNameProjectBudgetLocation 1MktJohnA100000MI 1MktJohnB200000IN 2EngJimA100000MI 3AcctJoeC350000IL 1MktJohnD250000MN 2EngJimD250000MN null !!null E400000WI Insert new projects

Deletion Anomaly EmpIDDeptNameProjectBudgetLocation 1MktJohnA100000MI 1MktJohnB200000IN 2EngJimA100000MI 3AcctJoeC350000IL EMPLOYEE-PROJECT EmpIDDeptNameProjectBudgetLocation 2EngJimA100000MI 3AcctJoeC350000IL Delete employee # 1 EmpIDDeptNameProjectBudgetLocation 1MktJohnB200000IN 3AcctJoeC350000IL Delete project A

Update Anomaly EmpIDDeptNameProjectBudgetLocation 1MktJohnA100000MI 1MktJohnB200000IN 2EngJimA100000MI 3AcctJoeC350000IL EMPLOYEE-PROJECT EmpIDDeptNameProjectBudgetLocation 1FinJohnA100000MI 1FinJohnB200000IN 2EngJimA100000MI 3AcctJoeC350000IL Update employees # 1

Normalization Theory Basic Concept - Functional Dependency Functional Dependency (FD): A relationship between attributes of an entity. FD is the foundation of Normalization. Notation: a  b - v alue of a uniquely determines the value of b  a is a “determinant”  a functionally determines b  b is functionally dependent on a

Normalization Theory Functional Dependency - Examples Interpretation: either SSN or EmpID can uniquely determine his/her Name, Phone, and DOB, but not the reverse! Both SSN and EmpID are candidate keys You can choose one of them as a PK SSN NamePhoneDOB EmpID EMPLOYEE ( SSN, EmpID, Name, Phone, DOB ) or EMPLOYEE ( SSN, EmpID, Name, Phone, DOB )

Normalization Theory Functional Dependency - Examples VIN # of doors ColorType Interpretation: VIN can uniquely determine a vehicle’s # of doors, Color, and Type, but not the reverse! VEHICLE ( VIN, # of doors, Color, Type ) VIN is the only candidate key and it is used as a PK

Database Normalization Where is the beef? Reality is not that simple ! All candidate keys, including PK, are the determinant But, determinant may not be the candidate key Q: What is the difference between a candidate key and a determinant? A: They are similar, but not the same - Scope

Database Normalization Where is the beef? Call # is a candidate key and is used as a PK Call # is also a determinant of CourseID, Title, and Classroom CourseID is a determinant of Title Q: Should we put these four attributes on the same table (relation)? A: No !! We need database normalization Title Call # ClassroomCourseID

Database Normalization Basic Ideas Unnormalized 1st NF (1NF) 2nd NF (2NF) 3rd NF (3NF)

Database Normalization Normal Form Definitions A relation is in its first normal form (1NF) if it does not contain repeating groups. A relation is in its second normal form (2NF) if every non-primary key attribute is fully dependent on the (whole) primary key. A relation is in its third normal form (3NF) if it has no transitive dependency between non-key attributes.

First Normal Form (1NF) 1NF: A relation is in its first normal form (1NF) if it does not contain repeating groups Phone SIDNameSexDOBPhone Major Repeating groups Normalization STUDENT ( SID, Name, Sex, DOB ) STU_PHONE ( SID, Phone ) STU_MAJOR ( SID, Major )

Second Normal Form (2NF) 2NF: A relation is in its second normal form (2NF) if it is in 1NF and every non- primary key attribute is fully functionally dependent on the (whole) primary key 123, Jim, Line crew, 01/01/96, Factory 123, Jim, Supervisor, 01/01/99, Factory 211, John, Sales Rep, 09/01/94, MKT 211, John, Sales Manager, 01/01/98, MKT 235, Joe, Accountant, 07/01/96, Acct A combination of EmpID and SDate is the only candidate key and is used as a PK (EmpID, SDate)  Name, Position, Dept EmpID  Name, Dept Q: Do we see any partially functional dependency? JOB_HIST ( EmpID, Name, Position, SDate, Dept )

Second Normal Form (2NF) JOB_HIST ( EmpID, Name, Position, SDate, Dept ) Normalization JOB_HIST ( EmpID, SDate, Position ) EMPLOYEE ( EmpID, Name, Dept )

Comments on 2NF Verification You don’t need to worry about whether a relation is in its 2NF if its PK includes only one attribute (Why?) Because Partially functional dependency only occurs when the PK is a composite (compound) key

Third Normal Form (3NF) 3NF: A relation is in its third normal form (3NF) if it is in 2NF and there is no transitive dependency between non-key attributes in the relation Transitive dependency: If a  b, and b  c, then there is a transitive dependency between a and c EmpID  Name, Phone, Office, Street, City, State, Zip Phone  Office Zip  City, State Q: Do you see the transitive dependency? EMPLOYEE ( EmpID, Name, Phone, Office, Street, City, State, Zip )

Third Normal Form (3NF) EMPLOYEE ( EmpID, Name, Phone, Office, Street, City, State, Zip ) Normalization EMPLOYEE ( EmpID, Name, Phone, Street, Zip ) PHONE ( Phone, Office ) ZIP ( Zip, City, State )