Normalisation 2 Chapter 4.2 V3.0 Napier University Dr Gordon Russell.

Slides:



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

Chapter 5 Normalization of Database Tables
Chapter 2.1 V3.1 Napier University Dr Gordon Russell
Normalisation 1 Chapter 4.1 V3.0 Napier University Dr Gordon Russell.
Normalisation. Informal guidelines  Semantics of the attributes  easy to explain relation  doesn’t mix concepts  Reducing the redundant values in.
 Definition  Components  Advantages  Limitations Contents  Definition Definition  Normal Forms Normal Forms  First Normal Form First Normal Form.
Normalisation to 3NF Database Systems Lecture 11 Natasha Alechina.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Boyce-Codd NF Takahiko Saito Spring 2005 CS 157A.
Normalisation The theory of Relational Database Design.
Normalization of Database Tables
3NF and Boyce-Codd Normal Form Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Fundamentals, Design, and Implementation, 9/e Chapter 4 The Relational Model and Normalization.
Need for Normalization
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
Normalization of Database Tables
Normalization of Database Tables
Chapter 5 Normalization of Database Tables
Project and Data Management Software
NORMALIZATION N. HARIKA (CSC).
Normalization Also called “loss-less decomposition”
Chapter 3 The Relational Model and Normalization
Normalization B Database Systems Normal Forms Wilhelm Steinbuss Room G1.25, ext. 4041
Normalization.
Chapter 5 Normalization of Database Tables
DBSQL 4-1 Copyright © Genetic Computer School 2009 Chapter 4 Database Design.
Lecture 12 Inst: Haya Sammaneh
Avoiding Database Anomalies
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
RDBMS Concepts/ Session 3 / 1 of 22 Objectives  In this lesson, you will learn to:  Describe data redundancy  Describe the first, second, and third.
Concepts of Database Management, Fifth 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.
Lecture 6 Normalization: Advanced forms. Objectives How inference rules can identify a set of all functional dependencies for a relation. How Inference.
Database Design (Normalizations) DCO11310 Database Systems and Design By Rose Chang.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
CSC271 Database Systems Lecture # 28.
Normalization Well structured relations and anomalies Normalization First normal form (1NF) Functional dependence Partial functional dependency Second.
By Abdul Rashid Ahmad. E.F. Codd proposed three normal forms: The first, second, and third normal forms 1NF, 2NF and 3NF are based on the functional dependencies.
3NF and Boyce-Codd Normal Form Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Lecture No 14 Functional Dependencies & Normalization ( III ) Mar 04 th 2011 Database Systems.
Normalization of Database Tables
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.
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.
Dr Gordon Russell, Napier University Normalisation 2 - V2.0 1 Normalisation 2 Unit 3.2.
Normalization. Overview Earliest  formalized database design technique and at one time was the starting point for logical database design. Today  is.
NormalisationNormalisation Normalization is the technique of organizing data elements into records. Normalization is the technique of organizing data elements.
Objectives of Normalization  To create a formal framework for analyzing relation schemas based on their keys and on the functional dependencies among.
SLIDE 1IS 257 – Fall 2006 Normalization Normalization theory is based on the observation that relations with certain properties are more effective.
MS Access. Most A2 projects use MS Access Has sufficient depth to support a significant project. Relational Databases. Fairly easy to develop a good user.
1 CS490 Database Management Systems. 2 CS490 Database Normalization.
Dr Gordon Russell, Napier University Normalisation 1 - V2.0 1 Normalisation 1 Unit 3.1.
Logical Design & the Relational Model
Advanced Normalization
Normalization Karolina muszyńska
Advanced Normalization
Chapter 6 Normalization of Database Tables
CSCI 2141 – Intro to Database Systems Database Normalization
CS 3630 Database Design and Implementation
Boyce-Codd Normal Form (BCNF)
Chapter 4.1 V3.0 Napier University Dr Gordon Russell
Normalization.
Normalization Normalization theory is based on the observation that relations with certain properties are more effective in inserting, updating and deleting.
Normalization February 28, 2019 DB:Normalization.
Database Normalization.
Chapter 4 The Relational Model and Normalization
Normalisation 1 Unit 3.1 Dr Gordon Russell, Napier University
Presentation transcript:

Normalisation 2 Chapter 4.2 V3.0 Napier University Dr Gordon Russell

Normalisation 2 Overview –normalise a relation to Boyce Codd Normal Form (BCNF) –An example

Boyce-Codd Normal Form (BCNF) When a relation has more than one candidate key, anomalies may result even though the relation is in 3NF. 3NF does not deal satisfactorily with the case of a relation with overlapping candidate keys –i.e. composite candidate keys with at least one attribute in common. BCNF is based on the concept of a determinant. –A determinant is any attribute (simple or composite) on which some other attribute is fully functionally dependent. A relation is in BCNF is, and only if, every determinant is a candidate key.

The theory Consider the following relation and determinants. R(a,b,c,d) a,c -> b,d a,d -> b To be in BCNF, all valid determinants must be a candidate key. In the relation R, a,c->b,d is the determinate used, so the first determinate is fine. a,d->b suggests that a,d can be the primary key, which would determine b. However this would not determine c. This is not a candidate key, and thus R is not in BCNF.

Example 1 Patient NoPatient NameAppointment IdTimeDoctor 1John009:00Zorro 2Kerr009:00Killer 3Adam110:00Zorro 4Robert013:00Killer 5Zane114:00Zorro

Two possible keys DB(Patno,PatName,appNo,time,doctor) Determinants: –Patno -> PatName –Patno,appNo -> Time,doctor –Time -> appNo Two options for 1NF primary key selection: – DB(Patno,PatName,appNo,time,doctor) (example 1a) – DB(Patno,PatName,appNo,time,doctor) (example 1b)

Example 1a DB(Patno,PatName,appNo,time,doctor) No repeating groups, so in 1NF 2NF – eliminate partial key dependencies: –DB(Patno,appNo,time,doctor) –R1(Patno,PatName) 3NF – no transient dependences so in 3NF Now try BCNF.

BCNF Every determinant is a candidate key DB(Patno,appNo,time,doctor) R1(Patno,PatName) Is determinant a candidate key? –Patno -> PatName Patno is present in DB, but not PatName, so irrelevant.

Continued … DB(Patno,appNo,time,doctor) R1(Patno,PatName) –Patno,appNo -> Time,doctor All LHS and RHS present so relevant. Is this a candidate key? Patno,appNo IS the key, so this is a candidate key. –Time -> appNo Time is present, and so is appNo, so relevant. Is this a candidate key? If it was then we could rewrite DB as: DB(Patno,appNo,time,doctor) This will not work, so not BCNF.

Rewrite to BCNF DB(Patno,appNo,time,doctor) R1(Patno,PatName) BCNF: rewrite to DB(Patno,time,doctor) R1(Patno,PatName) R2(time,appNo) time is enough to work out the appointment number of a patient. Now BCNF is satisfied, and the final relations shown are in BCNF

Example 1b DB(Patno,PatName,appNo,time,doctor) No repeating groups, so in 1NF 2NF – eliminate partial key dependencies: –DB(Patno,time,doctor) –R1(Patno,PatName) –R2(time,appNo) 3NF – no transient dependences so in 3NF Now try BCNF.

BCNF Every determinant is a candidate key DB(Patno,time,doctor) R1(Patno,PatName) R2(time,appNo) Is determinant a candidate key? –Patno -> PatName Patno is present in DB, but not PatName, irrelevant. –Patno,appNo -> Time,doctor Not all LHS present so not relevant –Time -> appNo Time is present, but not appNo, so not relevant. –Relations are in BCNF.

Summary - Example 1 This example has demonstrated three things: BCNF is stronger than 3NF, relations that are in 3NF are not necessarily inBCNF BCNF is needed in certain situations to obtain full understanding of the data model there are several routes to take to arrive at the same set of relations in BCNF. –Unfortunately there are no rules as to which route will be the easiest one to take.

Example 2 Grade_report(StudNo,StudName,(Major,Adviser, (CourseNo,Ctitle,InstrucName,InstructLocn,Grade))) Functional dependencies –StudNo -> StudName –CourseNo -> Ctitle,InstrucName –InstrucName -> InstrucLocn –StudNo,CourseNo,Major -> Grade –StudNo,Major -> Advisor –Advisor -> Major

Example 2 cont... Unnormalised Grade_report(StudNo,StudName,(Major,Advisor, (CourseNo,Ctitle,InstrucName,InstructLocn,Grade))) 1NF Remove repeating groups –Student(StudNo,StudName) –StudMajor(StudNo,Major,Advisor) –StudCourse(StudNo,Major,CourseNo, Ctitle,InstrucName,InstructLocn,Grade)

Example 2 cont... 1NF Student(StudNo,StudName) StudMajor(StudNo,Major,Advisor) StudCourse(StudNo,Major,CourseNo, Ctitle,InstrucName,InstructLocn,Grade) 2NF Remove partial key dependencies Student(StudNo,StudName) StudMajor(StudNo,Major,Advisor) StudCourse(StudNo,Major,CourseNo,Grade) Course(CourseNo,Ctitle,InstrucName,InstructLocn)

Example 2 cont... 2NF Student(StudNo,StudName) StudMajor(StudNo,Major,Advisor) StudCourse(StudNo,Major,CourseNo,Grade) Course(CourseNo,Ctitle,InstrucName,InstructLocn) 3NF Remove transitive dependencies Student(StudNo,StudName) StudMajor(StudNo,Major,Advisor) StudCourse(StudNo,Major,CourseNo,Grade) Course(CourseNo,Ctitle,InstrucName) Instructor(InstructName,InstructLocn)

Example 2 cont... BCNF Every determinant is a candidate key –Student : only determinant is StudNo –StudCourse: only determinant is StudNo,Major –Course: only determinant is CourseNo –Instructor: only determinant is InstrucName –StudMajor: the determinants are StudNo,Major, or Advisor Only StudNo,Major is a candidate key.

Example 2: BCNF BCNF Student(StudNo,StudName) StudCourse(StudNo,Major,CourseNo,Grade) Course(CourseNo,Ctitle,InstrucName) Instructor(InstructName,InstructLocn) StudMajor(StudNo,Advisor) Adviser(Adviser,Major)

Problems BCNF overcomes If the record for student 456 is deleted we lose not only information on student 456 but also the fact that DARWIN advises in BIOLOGY we cannot record the fact that WATSON can advise on COMPUTING until we have a student majoring in COMPUTING to whom we can assign WATSON as an advisor. STUDENTMAJORADVISOR 123PHYSICSEINSTEIN 123MUSICMOZART 456BIOLOGYDARWIN 789PHYSICSBOHR 999PHYSICSEINSTEIN

Split into two tables In BCNF we have two tables STUDENTADVISOR 123EINSTEIN 123MOZART 456DARWIN 789BOHR 999EINSTEIN ADVISORMAJOR EINSTEINPHYSICS MOZARTMUSIC DARWINBIOLOGY BOHRPHYSICS

Returning to the ER Model Now that we have reached the end of the normalisation process, you must go back and compare the resulting relations with the original ER model –You may need to alter it to take account of the changes that have occurred during the normalisation process Your ER diagram should always be a prefect reflection of the model you are going to implement in the database, so keep it up to date! –The changes required depends on how good the ER model was at first!

Video Library Example A video library allows customers to borrow videos. Assume that there is only 1 of each video. We are told that: video(title,director,serial) customer(name,addr,memberno) hire(memberno,serial,date) title->director,serial serial->title serial->director name,addr -> memberno memberno -> name,addr serial,date -> memberno

What NF is this? No repeating groups therefore at least 1NF 2NF – A Composite key exists: hire(memberno,serial,date) –Can memberno be found with just serial or date? –NO, therefore the relations are already in 2NF. 3NF?

Test for 3NF video(title,director,serial) –title->director,serial –serial->director Director can be derived using serial, and serial and director are both non keys, so therefore this is a transitive or non-key dependency. Rewrite video …

Rewrite for 3NF video(title,director,serial) –title->director,serial –serial->director Becomes: video(title,serial) serial(serial,director)

Check BCNF Is every determinant a candidate key? video(title,serial) - Determinants are: – title->director,serial Candidate key – serial->title Candidate key –video in BCNF serial(serial,director) Determinants are: –serial->director Candidate key –serial in BCNF

customer(name,addr,memberno) Determinants are: –name,addr -> memberno Candidate key –memberno -> name,addr Candidate key –customer in BCNF hire(memberno,serial,date) Determinants are: –serial,date -> memberno Candidate key –hire in BCNF Therefore the relations are also now in BCNF.