Database Normalisation

Slides:



Advertisements
Similar presentations
Functional Dependencies and Normalization for Relational Databases
Advertisements

Normalisation The theory of Relational Database Design.
Ch 10, Functional Dependencies and Normal forms
Functional Dependencies and Normalization for Relational Databases.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Normalization.
Ms. Hatoon Al-Sagri CCIS – IS Department Normalization.
Functional Dependencies and Normalization for Relational Databases
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
METU Department of Computer Eng Ceng 302 Introduction to DBMS Functional Dependencies and Normalization for Relational Databases by Pinar Senkul resources:
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Introduction to Schema Refinement. Different problems may arise when converting a relation into standard form They are Data redundancy Update Anomalies.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Functional Dependencies and Normalization for Relational Databases.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 6 NORMALIZATION FOR RELATIONAL DATABASES Instructor Ms. Arwa Binsaleh.
Week 6 Lecture Normalization
King Saud University College of Computer & Information Sciences Computer Science Department CS 380 Introduction to Database Systems Functional Dependencies.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Topic 10 Functional Dependencies and Normalization for Relational Databases Faculty of Information Science and Technology Mahanakorn University of Technology.
Instructor: Churee Techawut Functional Dependencies and Normalization for Relational Databases Chapter 4 CS (204)321 Database System I.
Functional Dependencies and Normalization for Relational Databases.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Normalization Well structured relations and anomalies Normalization First normal form (1NF) Functional dependence Partial functional dependency Second.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Chapter Functional Dependencies and Normalization for Relational Databases.
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 10 Functional Dependencies and Normalization for Relational Databases.
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 10 Functional Dependencies and Normalization for Relational Databases.
COMP1212 COMP1212 Anomalies and Dependencies Dr. Mabruk Ali.
1 Functional Dependencies and Normalization Chapter 15.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Lecture 8: Database Concepts May 4, Outline From last lecture: creating views Normalization.
Database Design FUNCTIONAL DEPENDENCES NORMAL FORMS D. Christozov / G.Tuparov INF 280 Database Systems: DB design: Normal Forms 1.
Chapter 7 Functional Dependencies Copyright © 2004 Pearson Education, Inc.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Deanship of Distance Learning Avicenna Center for E-Learning 1 Session - 7 Sequence - 1 Normalization DB Design Guidelines Presented by: Dr. Samir Tartir.
Al-Imam University Girls Education Center Collage of Computer Science 1 st Semester, 1432/1433H Chapter 10_part 1 Functional Dependencies and Normalization.
NormalisationNormalisation Normalization is the technique of organizing data elements into records. Normalization is the technique of organizing data elements.
Chapter 15 1 Functional Dependencies and Normalization for Relational Databases تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة من الادوات في.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Chapter 14 Functional Dependencies and Normalization Informal Design Guidelines for Relational Databases –Semantics of the Relation Attributes –Redundant.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
10/3/2017.
10/3/2017.
Normalization.
COP 6726: New Directions in Database Systems
Functional Dependency and Normalization
CHAPTER 14 Basics of Functional Dependencies and Normalization for Relational Databases.
Functional Dependencies and Normalization for Relational Databases
Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases.
Chapter 14 Normalization
Normalization 2NF & 3NF Presented by: Dr. Samir Tartir
Functional Dependencies and Normalization for Relational Databases
Database Management systems Subject Code: 10CS54 Prepared By:
Database Normalization
Chapter 14 Normalization – Part I Pearson Education © 2009.
Normalization Dale-Marie Wilson, Ph.D..
Normalization.
Normalization DB Design Guidelines Presented by: Dr. Samir Tartir
Normalization February 28, 2019 DB:Normalization.
國立臺北科技大學 課程:資料庫系統 2015 fall Chapter 14 Normalization.
Sampath Jayarathna Cal Poly Pomona
NORMALIZATION FIRST NORMAL FORM (1NF):
Chapter Outline 1 Informal Design Guidelines for Relational Databases
Relational Databases.
Presentation transcript:

Database Normalisation

Introduction Two levels of relation schemas General Guidelines: The logical "user view" level The storage "base relation" level General Guidelines: Informally, each tuple in a relation should represent one entity or relationship instance. Attributes of different entities (EMPLOYEEs, DEPARTMENTs, PROJECTs) should not be mixed in the same relation Only foreign keys should be used to refer to other entities Entity and relationship attributes should be kept apart as much as possible.

A simplified COMPANY relational database schema

What is normalisation Divide into tables Relations among tables using primary/foreign keys Minimal redundancy Grouping correlated data in one place One place for modifications Based on functional dependencies

Functional dependency A  B means that each value of A is always associated with one value of B. The opposite is false. A  B holds if whenever two tuples have the same value for A, they must have the same value for B Read as: - B is functionally dependent on A - A is a determinant of B Partial functional dependency occur when A is composite of more than one attribute, and B is functionally dependent on one attribute of A’s attributes. Full Functional Dependency is when B is functionally dependent on A, and not any proper subset of A. Transitive dependence: ABC, it is between A and C via B

Functional dependency Examples: {SSN, PNUMBER} -> HOURS is a full FD since neither SSN -> HOURS nor PNUMBER -> HOURS hold {SSN, PNUMBER} -> ENAME is not a full FD (it is called a partial dependency ) since SSN -> ENAME also holds

Process of normalisation 3NF 2NF 1NF UNF Remove repeating groups (Multi-valued) Remove partial dependencies Remove transitive dependencies

UNF A table (relation) that contains one or more repeating groups Vertically: some blank cells Horizontally: no blank cells

1NF Remove repeated groups To make the UNF in 1NF: Vertically: simply fill the blanks

1NF To make the UNF in 1NF: Horizontally: separate into two tables Put the repeated groups in separate table with a foreign key

So far ... The relation has a primary key If the key is with single-attributes, the relation now in, at least, 2NF If the key is composite-key, the relation now in, at least,1NF Functional dependency is not used so far 1NF: A relation in which the intersection of each row and column contains one and only one value

2NF Remove partial dependencies That is; every non-key attribute depends on the whole of the primary key, and not just a part (subset) of it. In other words, fully functional dependency. 2NF A relation that is in 1NF and every non-primary-key attribute is fully functionally dependent on the primary key. Still, transitive dependency might exist.

Part of example on 2NF 1NF 2NF

Part of example on 2NF 1NF 2NF

3NF Remove transitive dependencies OR non-key attributes are dependent on the key only Remove the non-key attributes that do not depend on the key 3NF: A relation that is in 1NF and 2NF and in which no non-primary-key attribute is transitively dependent on the primary key

Part of example on 3NF 1NF 2NF

Part of example on 3NF 2NF 3NF

Examples

Example 1 UNF 1NF

Example 1 2NF

Example 1 2NF 3NF

Example 2 (assumption 1) One action may shift the relation two levels. More than one action might be taken to shift the relation one level. In the following example, we assumed that the employee can work only in one department. Therefore, the PK is the emp# and the relation is in the 2NF (no partial functional dependency).

Example 2 (emp# is the PK) Employee table 2NF emp# emp_name salary dept# dept_name dept_mngr Mngr_address Employee table emp# emp_name salary dept# Department table dept# dept_name dept_mngr Mngr_address Department table Employee table 3NF dept# dept_name dept_mngr emp# emp_name salary dept# Manager table dept_mngr Mngr_address

Example 2 (assumption 2) Assuming that the employee can work in more than one department makes the PK(emp#, dept#) and thus, the relation is in the 1NF (there is partial functional dependency).

Example 2 ((emp#, dept#) is the PK) Employee table 1NF emp# emp_name salary dept# dept_name dept_mngr Mngr_address Employee table emp# emp_name salary 2NF Original table Department table dept# dept_name dept_mngr Mngr_address emp# dept# Employee table Original table emp# emp_name salary 3NF emp# dept# Manager table Department table dept_mngr Mngr_address dept# dept_name dept_mngr

Example 3 3NF car# Model Colour Engine_id Max_speed Petrol_type Width

Fill the blanks to be in 1NF Example 4 Assume that the Dept. # and Cust. # are all needed to uniquely identify the date and nature of the complaint about the department. Dept # Dept Name Location Mgr Name Mgr ID No. Tel Extn. Cust # Cust Name Date of Complaint Nature of Complaint 11232 Soap Division Cincinnati Mary Samuel S11 7711 P10451 Robert Drumtree 12/01/1998 Poor Service   P10480 Steven Parks 14/01/1998 Discourteous Attendant UNF Fill the blanks to be in 1NF Dept # Cust # Date of Complaint Nature of Complaint Dept Name Location Mgr Name Mgr ID No. Tel Extn. Cust Name 2NF Dept # Cust # Date of Complaint Nature of Complaint Dept Name Location Mgr ID No. Tel Extn. Cust Name Mgr Name 3NF

Anomaly

Redundant Information in Tuples and Anomalies If information is stored redundantly Wastes storage Causes problems with update anomalies Insertion anomalies Deletion anomalies Modification anomalies

EXAMPLE OF AN UPDATE ANOMALY Consider the relation: Storing project name and employee name in the Emp_Proj table: EMP_PROJ (Emp#, Proj#, Ename, Pname, No_hours) Update Anomaly: Changing the name of project number P1 from “Billing” to “Customer-Accounting” may cause this update to be made for all 100 employees working on project P1. Same goes for changing an employee name.

EXAMPLE OF AN INSERT ANOMALY Consider the relation: EMP_PROJ (Emp#, Proj#, Ename, Pname, No_hours) Insert Anomaly: Cannot insert a project unless an employee is assigned to it. Cannot insert an employee unless a he/she is assigned to a project.

EXAMPLE OF AN DELETE ANOMALY Consider the relation: EMP_PROJ(Emp#, Proj#, Ename, Pname, No_hours) Delete Anomaly: When a project is deleted, it will result in deleting all the employees who work on that project. Alternately, if an employee is the only employee on a project, deleting that employee would result in deleting the corresponding project.

Two relation schemas suffering from update anomalies

Relations formed after a Natural Join

The End