THE RELATIONAL MODEL II IST 210: Organization of Data IST210 1.

Slides:



Advertisements
Similar presentations
Boyce-Codd normal form (BCNF) Kai Zhu CS157B Professor: Dr. Lee.
Advertisements

Normalization Process: Exercise 2: Step 1 IST2101 Step 1. Identify all the candidate keys of the relation. (Attorney, ClientNumber, MeetingDate)
Normal Forms By Christopher Archibald October 16 th 2007.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 7 th Edition.
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.
The Relational Model Chapter Two Functional Dependency.
Fundamentals, Design, and Implementation, 9/e Chapter 4 The Relational Model and Normalization.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 3-1 COS 346 Day 5.
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
Boyce-Codd Normal Form Kelvin Nishikawa SE157a-03 Fall 2006 Kelvin Nishikawa SE157a-03 Fall 2006.
1 5 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 5 Database Design: Normalization.
Database Normalization Il-Han Yoo CS 157A Professor: Sin-Min Lee.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 3-1 David M. Kroenke Database Processing Chapter 3 Normalization.
Normalization I.
The Relational Model Chapter Two (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 5 The Relational Model and Normalization.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value.
1 5 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 5 Database Design 1: Normalization.
Normalization II. Boyce–Codd Normal Form (BCNF) Based on functional dependencies that take into account all candidate keys in a relation, however BCNF.
DBSQL 4-1 Copyright © Genetic Computer School 2009 Chapter 4 Database Design.
Lecture 12 Inst: Haya Sammaneh
Copyright, Harris Corporation & Ophir Frieder, Normal Forms “Why be normal?” - Author unknown Normal.
Chapter 5 The Relational Model and Normalization David M. Kroenke Database Processing © 2000 Prentice Hall.
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
Avoiding Database Anomalies
Normalization. 2 Objectives u Purpose of normalization. u Problems associated with redundant data. u Identification of various types of update anomalies.
NormalizationNormalization Chapter 4. Purpose of Normalization Normalization  A technique for producing a set of relations with desirable properties,
Concepts of Database Management Sixth Edition Chapter 5 Database Design 1: Normalization.
Concepts of Database Management, Fifth Edition
Database Management COP4540, SCS, FIU Relation Normalization (Chapter 14)
The Relational Model and Normalization R. Nakatsu.
Lecture 6 Normalization: Advanced forms. Objectives How inference rules can identify a set of all functional dependencies for a relation. How Inference.
Objectives of Normalization Develop a good description of the data, its relationships and constraints Produce a stable set of relations that Is a faithful.
SALINI SUDESH. Primarily a tool to validate and improve a logical design so that it satisfies certain constraints that avoid unnecessary duplication of.
Schema Refinement and Normal Forms 20131CS3754 Class Notes #7, John Shieh.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall, Modified by Dr. Mathis 3-1 David M. Kroenke’s Chapter Three: The Relational.
The Relational Model Chapter Two DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 3 rd Edition.
Normalization Process: Exercise 1: Step 1 IST2101 Step 1. Identify all the candidate keys of the relation. StudentNumber.
CSE314 Database Systems Basics of Functional Dependencies and Normalization for Relational Databases Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E.
11/07/2003Akbar Mokhtarani (LBNL)1 Normalization of Relational Tables Akbar Mokhtarani LBNL (HENPC group) November 7, 2003.
Chapter 2. The Relational Model (cont.)
Data Analysis Improving Database Design. Normalization The process of transforming a data model into a flexible, stable structure. Reduces anomalies Anomaly.
Dr. Mohamed Osman Hegaz1 Logical data base design (2) Normalization.
Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 4/1 Copyright © 2004 Please……. No Food Or Drink in the class.
What is normalization ? Proposed by Codd in 1972 Takes a relation through a series of steps to certify whether it satisfies a certain normal form Initially.
9/23/2012ISC329 Isabelle Bichindaritz1 Normalization.
Chapter 2. The Relational Model (cont.) IST2101. Review: Determinant vs. Candidate Key IST2102 DeterminantsCandidate Key (StudentID, CourseID) StudentID.
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 MIS335 Database Systems. Why Normalization? Optimizing database structure Removing duplications Accelerating the instructions Data integrity!
Concepts of Database Management Seventh Edition Chapter 5 Database Design 1: Normalization.
THE RELATIONAL MODEL I IST 210: Organization of Data IST210 1.
© 2002 by Prentice Hall 1 The Relational Model David M. Kroenke Database Concepts 1e Chapter 2 2.
Brian Thoms.  Databases normalization The systematic way of ensuring that a database structure is suitable for general-purpose querying and free of certain.
11/10/2009GAK1 Normalization. 11/10/2009GAK2 Learning Objectives Definition of normalization and its purpose in database design Types of normal forms.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 5 The Relational Model and Normalization.
Normal Forms (Part 1) Steven Le ~ CS157B. Normalization is a systematic way of ensuring that a database structure is suitable for general-purpose querying.
Logical Database Design and Relational Data Model Muhammad Nasir
1 CS490 Database Management Systems. 2 CS490 Database Normalization.
1 Normalization David J. Stucki. Outline Informal Design Guidelines Normal Forms  1NF  2NF  3NF  BCNF  4NF 2.
The Relational Model and Database Normalization
The Relational Model Chapter Two DATABASE CONCEPTS, 3rd Edition
ISQS 6339, Business Intelligence Database vs. Data Warehouse
The Relational Model and Normalization
Copyright © 2018, 2015, 20 Pearson Education, Inc. All Rights Reserved Database Concepts Eighth Edition Chapter # 2 The Relational Model.
Chapter 4 The Relational Model and Normalization
Database.
Presentation transcript:

THE RELATIONAL MODEL II IST 210: Organization of Data IST210 1

How to design a well-formed model? Revisit assignment 1 Break list into tables How to split? Functional Dependency  important criteria Normalization Process  process to design a well-formed model IST210 2

Functional Dependency A relationship between attributes: some attribute(s) determine the value of other attribute(s) in the same table These attributes we name them determinant The other attributes are functionally dependent on this determinant IST210 3 CookieCost = NumberOfBoxes * $5 NumberOfBoxes  CookieCost CookieCost = NumberOfBoxes * UnitPrice (UnitPrice, NumberOfBoxes)  CookieCost determinant The composite forms determinant Functionally dependent on NumberofBoxes

Determinant in Relations IST210 4 StudentI D FirstNameLastNameDOB JohnSmithJan. 1, JohnAdamJun. 1, JaneAdamAug. 1, JoshCohenAug. 1,1989 ClubIDClubNamePresident 12Football Medical Dance Determinant: StudentID Determinant: ClubID Determinant: CourseID Determinant = Candidate key?

Review: Candidate Key A candidate key is a special key Any subset of a candidate key is NOT a key (StudentID, FirstName) is not a candidate key, because StudentID is a key IST210 5

Determinant = Candidate Key? Student ID Student Name Student's Department CourseIDInstructorCourseNameLocation 1BobIST 210JessieOrganization of Data110IST 5LisaIST 210JessieOrganization of Data110IST 2SarahIST 210JessieOrganization of Data110IST 3JimCSE 210JessieOrganization of Data110IST 1BobIST 220JohnNetwork208IST 3JimCSE 220JohnNetwork208IST 10KateIST 230DavidComputer Language206IST IST210 6 DeterminantsCandidate Key (StudentID, CourseID) StudentID CourseID (StudentID, CourseID) In a relation, a candidate key must be a determinant In a relation, a determinant may not be a candidate key If every determinant is a candidate key, it is a well-formed relation.

Normalization Normalization is a process of analyzing a relation to ensure that it is well formed No data redundancy among the nonkey attributes Data can be inserted, deleted, or modified without creating update anomalies IST210 7

Normalization Principles Relational design principle for normalized relations: To be a well-formed relation, every determinant must be a candidate key Any relation that is not well formed should be broken into two or more well-formed relations IST210 8

Normalization Process 1. Identify all the candidate keys of the relation. 2. Identify all the functional dependencies in the relation. 3. Examine the determinants of the functional dependencies. If any determinant is not a candidate key, the relation is not well formed. In this case: a. Place the columns of the functional dependency in a new relation of their own. b. Make the determinant of the functional dependency the primary key of the new relation. c. Leave a copy of the determinant as a foreign key in the original relation. d. Create a referential integrity constraint between the original relation and the new relation. 4. Repeat step 3 as many times as necessary until every determinant of every relation is a candidate key. IST210 9

Normalization Process: Example 1: Step 1 IST Step 1. Identify all the candidate keys of the relation. PrescriptionNumber

Normalization Process: Example 1: Step 2 IST Step 2. Identify all the functional dependencies in the relation. Drug  Dosage? No Customer  (CustomerName, CustomerPhone)? Yes, in this example PrescriptionNumber  (Date, Drug, Dosage, CustomerName, CustomerPhone, Customer ) This is a trivial dependency by the definition of candidate key

Normalization Process: Example 1: Step 3 IST Step 3. If any determinant is not a candidate key, the relation is not well formed. Determinant: PrescriptionNumber, Customer Candidate key: PrescriptionNumber Customer is NOT a candidate key, so the relation NOT well formed Then, we will normalize it (break it into multiple relations)

Normalization Process: Example 1: Step 3 IST Step 3. Examine the determinants of the functional dependencies. If any determinant is not a candidate key, the relation is not well formed. In this case: a.Place the columns of the functional dependency in a new relation of their own. CUSTOMER (Customer , CustomerName, CustomerPhone) b.Make the determinant of the functional dependency the primary key of the new relation. CUSTOMER (Customer , CustomerName, CustomerPhone) c.Leave a copy of the determinant as a foreign key in the original relation. PRESCRIPTION(PrescriptionNumber, Date, Drug, Dosage, Customer ) d.Create a referential integrity constraint between the original relation and the new relation. Customer in PRESCRIPTION must exist in Customer in CUSTOMER

Normalization Process: Example 1: Step 4 IST Step 4. Repeat step 3 as many times as necessary until every determinant of every relation is a candidate key. CUSTOMER (Customer , CustomerName, CustomerPhone) PRESCRIPTION(PrescriptionNumber, Date, Drug, Dosage, Customer ) Customer in PRESCRIPTION must exist in Customer in CUSTOMER Well-formed relational model design

Normalization Process: Example 2 IST Step 1. Candidate keys Step 2. Functional dependencies Step 3. Split the relation

Normalization Process: Example 2: Step 1 IST Step 1. Identify all the candidate keys of the relation. StudentNumber

Normalization Process: Example 2: Step 2 IST Step 2. Identify all the functional dependencies in the relation. DormName  DormCost Trivial dependency: StudentNumber  (LastName, FirstName, DormName, DormCost)

Normalization Process: Example 2: Step 3 IST Step 3. If any determinant is not a candidate key, the relation is not well formed. StudentNumber StudentNumber  (LastName, FirstName, DormName, DormCost) DormName  DormCost

Normalization Process: Example 2: Step 3 IST Step 3. Examine the determinants of the functional dependencies. If any determinant is not a candidate key, the relation is not well formed. In this case: a.Place the columns of the functional dependency in a new relation of their own. DORM(DormName, DormCost) b.Make the determinant of the functional dependency the primary key of the new relation. DORM(DormName, DormCost) c.Leave a copy of the determinant as a foreign key in the original relation. STU_DORM(StudentNumber, LastName, FirstName, DormName) d.Create a referential integrity constraint between the original relation and the new relation. DormName in STU_DORM must exist in DormName in DORM

Normalization Process: Example 2: Step 4 IST Step 4. Repeat step 3 as many times as necessary until every determinant of every relation is a candidate key. STU_DORM(StudentNumber, LastName, FirstName, DormName) DORM(DormName, DormCost) DormName in STU_DORM must exist in DormName in DORM Well-formed relational model design

Normalization Process: Example 3 IST Step 1. Candidate keys Step 2. Functional dependencies Step 3. Split the relation

Normalization Process: Example 3: Step 1 IST Step 1. Identify all the candidate keys of the relation. (Attorney, ClientNumber, MeetingDate)

Normalization Process: Example 3: Step 2 IST Step 2. Identify all the functional dependencies in the relation. ClientNumber  ClientName Trivial dependency: (Attorney, ClientNumber, MeetingDate)  (ClientName, Duration)

Normalization Process: Example 3: Step 3 IST Step 3. If any determinant is not a candidate key, the relation is not well formed. (Attorney, ClientNumber, MeetingDate) (Attorney, ClientNumber, MeetingDate)  (ClientName, Duration) ClientNumber  ClientName

Normalization Process: Example 3: Step 3 IST Step 3. Examine the determinants of the functional dependencies. If any determinant is not a candidate key, the relation is not well formed. In this case: a.Place the columns of the functional dependency in a new relation of their own. CLIENT(ClientNumber, ClientName) b.Make the determinant of the functional dependency the primary key of the new relation. CLIENT(ClientNumber, ClientName) c.Leave a copy of the determinant as a foreign key in the original relation. MEETING(Attorney, ClientNumber, MeetingDate, Duration) ClientNumber: A foreign key and also part of primary key d.Create a referential integrity constraint between the original relation and the new relation. ClientNumber in MEETING must exist in ClientNumber in CLIENT

Normalization Process: Example 3: Step 4 IST Step 4. Repeat step 3 as many times as necessary until every determinant of every relation is a candidate key. CLIENT(ClientNumber, ClientName) MEETING(Attorney, ClientNumber, MeetingDate, Duration) ClientNumber in MEETING must exist in ClientNumber in CLIENT Well-formed relational model design

Normalization Process: Example 4 IST Student ID Student Name Student's Department CourseIDInstructorCourseNameLocation 1BobIST 210JessieOrganization of Data110IST 5LisaIST 210JessieOrganization of Data110IST 2SarahIST 210JessieOrganization of Data110IST 3JimCSE 210JessieOrganization of Data110IST 1BobIST 220JohnNetwork208IST 3JimCSE 220JohnNetwork208IST 10KateIST 230DavidComputer Language206IST Step 1. Candidate keys Step 2. Functional dependencies Step 3. Split the relation

Normalization Process: Example 4 IST Student ID Student Name Student's Department CourseIDInstructorCourseNameLocation 1BobIST 210JessieOrganization of Data110IST 5LisaIST 210JessieOrganization of Data110IST 2SarahIST 210JessieOrganization of Data110IST 3JimCSE 210JessieOrganization of Data110IST 1BobIST 220JohnNetwork208IST 3JimCSE 220JohnNetwork208IST 10KateIST 230DavidComputer Language206IST Step 1. Candidate keys (StudentID, CourseID)(StudentID, CourseID)  all other columns StudentID  (StudentName, Student’s Department, ) CourseID  (Instructor, CourseName, Location) STUDENT(StudentID, StudentName, Student’sDepartment, ) COURSE(CourseID, Instructor, CourseName, Location) REGISTRATION(StudentID, CourseID) StudentID in REGISTRATION must exist in StudentID in STUDENT COURSEID in REGISTRATION must exist in CourseID in COURSE Step 2. Functional dependencies Step 3. Split the relation

Normalization Process: Example 5 IST GRADE(ClassName, Section, Term, Grade, StudentNumber, StudentName, Professor, Department, Professor )

Normalization Process: Example 5: Step 1 IST Step 1. Identify all the candidate keys of the relation. (ClassName, Section, Term, StudentNumber) GRADE(ClassName, Section, Term, Grade, StudentNumber, StudentName, Professor, Department, Professor )

Normalization Process: Example 5: Step 2 IST Step 2. Identify all the functional dependencies in the relation. StudentNumber  StudentName Professor  (Department, Professor ) (Classname, Section, Term)  Professor GRADE(ClassName, Section, Term, Grade, StudentNumber, StudentName, Professor, Department, Professor ) Trivial dependency: (ClassName, Section, Term, StudentNumber)  (Grade, StudentName, Professor, Department, Professor )

Normalization Process: Example 5: Step 3 IST GRADE(ClassName, Section, Term, Grade, StudentNumber, StudentName, Professor, Department, Professor ) Step 3. If any determinant is not a candidate key, the relation is not well formed. (ClassName, Section, Term, StudentNumber) (ClassName, Section, Term, StudentNumber)  all other columns StudentNumber  StudentName Professor  (Department, Professor ) (Classname, Section, Term)  Professor

Normalization Process: Example 5: Step 3 IST Step 3. Examine the determinants of the functional dependencies. If any determinant is not a candidate key, the relation is not well formed. In this case: STUDENT(StudentNumber, StudentName) PROFESSOR(Professor, Department, Professor ) CLASS_PROFESSOR(ClassName, Section, Term, Professor) GRADE_1(ClassName, Section, Term, Grade, StudentNumber) StudentNumber in GRADE_1 must exist in StudentNumber in STUDENT Proessor in CLASS_PROFESSOR must exist in Professor in PROFESSOR (ClassName, Section, Term) in GRADE_1 must exist in (ClassName, Section, Term) of CLASS_PROFESSOR StudentNumber  StudentName Professor  (Department, Professor ) (Classname, Section, Term)  Professor (ClassName, Section, Term, StudentNumber)  all other columns

Normal Form The normal forms (abbrev. NF) of relational database theory provide criteria for determining a table's degree of vulnerability to logical inconsistencies and anomalies. In textbook, briefly mentioned in P. 261 This is an important theory in database IST210 34

IST Normal formBrief definition First normal formFirst normal form (1NF) Table faithfully represents a relation and has no repeating groupsrelation Second normal formSecond normal form (2NF) No non-prime attribute in the table is functionally dependent on a proper subset of any candidate keyfunctionally dependentproper subsetcandidate key Third normal formThird normal form (3NF) Every non-prime attribute is non-transitively dependent on every candidate key in the table. The attributes that do not contribute to the description of the primary key are removed from the table. In other words, no transitivity dependency is allowed.candidate key Elementary Key Normal Form Elementary Key Normal Form (EKNF) Every non-trivial functional dependency in the table is either the dependency of an elementary key attribute or a dependency on a superkey Boyce–Codd normal form Boyce–Codd normal form (BCNF) Every non-trivial functional dependency in the table is a dependency on a superkeysuperkey Fourth normal formFourth normal form (4NF) Every non-trivial multivalued dependency in the table is a dependency on a superkeymultivalued dependency Fifth normal formFifth normal form (5NF) Every non-trivial join dependency in the table is implied by the superkeys of the tablejoin dependency Domain/key normal form Domain/key normal form (DKNF) Every constraint on the table is a logical consequence of the table's domain constraints and key constraintslogical consequence Sixth normal formSixth normal form (6NF) Table features no non-trivial join dependencies at all (with reference to generalized join operator)

First Normal Form First normal form (1NF) is a property of a relation in a relational database. 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 IST Fail to comply 1NF Comply 1NF

Second Normal Form A table is in 2NF if and only if it is in 1NF and no non prime attribute is dependent on any proper subset of any candidate key of the table. IST Fail to comply 2NF Comply 2NF

Second Normal Form (cont.) A table is in 2NF if and only if it is in 1NF and no non prime attribute is dependent on any proper subset of any candidate key of the table. IST Comply 2NF?

Third Normal Form A table is in 3NF if and only if both of the following conditions hold: The relation R (table) is in second normal form (2NF) Every non-prime attribute of R is non-transitively dependent (i.e. directly dependent) on every super key of R. IST Fail to comply 3NF (Tournament, Year)  Winner Winner  Winner DOB Comply 3NF

Review Question A relation is well-formed if A. Every determinant is a candidate key. B. Every candidate key is a determinant. IST210 40

Summary of Chapter 2 Learn the concept of the relational model Learn the meaning and importance of keys, candidate keys, primary keys, foreign keys, and related terminology Learn the meaning of functional dependencies Learn to apply a process for normalizing relations IST210 41

Reminder Homework 2 is out – due Sept 14 th at 11:59PM No Class on Labor day IST210 42