Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture – 5 Course Code – MIS4102.  Edgar F. Codd, the inventor of the relational model, introduced the concept of normalization and what we now know.

Similar presentations


Presentation on theme: "Lecture – 5 Course Code – MIS4102.  Edgar F. Codd, the inventor of the relational model, introduced the concept of normalization and what we now know."— Presentation transcript:

1 Lecture – 5 Course Code – MIS4102

2  Edgar F. Codd, the inventor of the relational model, introduced the concept of normalization and what we now know as the First Normal Form (1NF) in 1970.  Codd went on to define the Second Normal Form (2NF) and Third Normal Form (3NF) in 1971, and Codd and Raymond F. Boyce defined the Boyce-Codd Normal Form (BCNF) in 1974.  Higher normal forms were defined by other theorists in subsequent years, Fagin introduced Forth and Fifth normal form (Fagin 1977, 1979).  The most recent being the Sixth Normal Form (6NF) introduced by Chris Date, Hugh Darwen, and Nikos Lorentzos in 2002. Introduction

3 Why Normalization?  The step-by-step process of identifying and eliminating data redundancies and inconsistencies is called normalization.  Tables are the basic building blocks of the database, so good database design must be matched with good table structures.  Normalization enables us to recognize bad table structures and allow us to create good table structures.

4 Redundancy & Anomalies  Data redundancy = data stored in several places Too much data redundancy causes problems-- which value is correct? Data integrity and consistency suffer  Data anomaly = abnormal data relationships Insertion anomaly - Can’t add data because don’t know entire primary key value, e.g., primary key based on first, middle, and last name Deletion anomaly - Deletions result in too many fields being removed unintentionally, e.g., delete an employee but lose transaction data Update anomaly - Change requires many updates, e.g., if you store customer names in transaction tables

5  Normalization stages are called normal forms (1NF, 2NF and 3NF) each better than previous (less anomalies/redundancy).  Highest level not always the most desirable.  Most professionally designed databases reach third normal form.  Fourth and Fifth normal forms are seldom used. Normalization (Cont…)

6 Non-loss Decomposition  The process of transforming an un- normalized data set into a fully normalized database is frequently referred to as a process of non-loss decomposition.  This is because we continually fragment our data structure into more tables without losing the fundamental relationships between data items.

7 Normalization Example  To recognize good design, first look at bad one  Example, construction company manages several projects and whose charges are dependent on employee’s position.

8 Desired Report Proj NoProj NameEmp NoEmp NameJob ClassChg/Hr ($)Hrs BilledTot Chg ($) 1Hurricane101Kamal HossainElec Eng6513845 102David PolComm Eng6016960 104Didar AhmedComm Eng60191,140 Sub Total2,945 2Coast101Kamal HossainElec Eng6515975 103Younus MiaAsst Eng5517935 Sub Total1,910 3Satellite104Didar AhmedComm Eng60181,080 102David PolComm Eng6014840 Sub Total1,920 Total6,775

9 Table view of the previous report P_NoP_NameE_NoE_NameJob_ClassChg_HrHrs 1Hurricane101Kamal HossainElec Eng6513 102David PolComm Eng6016 104Didar AhmedComm Eng6019 2Coast101Kamal HossainElec Eng6515 103Younus MiaAsst Eng5517 3Satellite104Didar AhmedComm Eng6018 102David PolComm Eng6014

10 Problems  P_No intended to be primary key but contains null values  Data redundancies Invites data inconsistencies (Elect Eng & EE) Wastes data entry time, wastes storage space  Anomalies Update anomaly – modify Job_Class for E_No 101 requires many alterations Insert anomaly – to add a project row we need an employee Deletion anomaly – delete E_No 101, we delete other vital data too

11 Problems (cont…)  Table above has repeating groups  Each P_No has a group of entries P_NoP_NameE_NoE_NameJob_ClassChg_HrHrs 1Hurricane101Kamal HossainElec Eng6513 102David PolComm Eng6016 104Didar AhmedComm Eng6019

12 Conversion to 1NF  Eliminate repeating groups  By adding entries in primary key column P_NoP_NameE_NoE_NameJob_ClassChg_HrHrs 1Hurricane101Kamal HossainElec Eng6513 1Hurricane102David PolComm Eng6016 1Hurricane104Didar AhmedComm Eng6019 2Coast101Kamal HossainElec Eng6515 2Coast103Younus MiaAsst Eng5517 3Satellite104Didar AhmedComm Eng6018 3Satellite102David PolComm Eng6014

13 Problems  Primary key P_No does not uniquely identify all attributes in row  Must create composite key made up of P_No & E_No

14 Dependency Diagram  Helps us to discover relationships between entity attributes  Upper arrows implies dependency on P_No & E_No  Lower arrows implies dependency on only one attribute P_NoP_NameE_NoE_NameJob_ClassChg_HrHrs

15 Dependencies  Upper arrows If you know P_No & E_No you can determine the other row values  Lower arrows Partial dependencies – based on only part of key P_Name only dependent on P_No E_Name, Job_Class, Chg_Hr only dependent on E_No  Dependency diagram may be written: P_No, E_No  P_Name, E_Name, Job_Class, Chg_Hr, Hrs P_No  P_Name E_No  E_Name, Job_Class, Chg_Hr

16 New Table (1NF)  Composite primary key P_No & E_No Charges Table P_NoP_NameE_NoE_NameJob_ClassChg_HrHrs 1Hurricane101Kamal HossainElec Eng6513 1Hurricane102David PolComm Eng6016 1Hurricane104Didar AhmedComm Eng6019 2Coast101Kamal HossainElec Eng6515 2Coast103Younus MiaAsst Eng5517 3Satellite104Didar AhmedComm Eng6018 3Satellite102David PolComm Eng6014

17 1NF Definition 1.All the key attributes are defined Any attribute that is part of the primary key 2.There are no repeating groups in the table Each cell can contain one and only one value, rather than set 3.All attributes are dependent on the primary key

18 Problem - Partial Dependencies  Contains partial dependencies Dependencies base on only part of the primary key  This makes table subject to data redundancies and hence to data anomalies  Redundancy caused by fact that every row entry requires duplicate data E.g., suppose E_No 104 is entered 20 times, must also enter E_Name, Job_Class, Chg_Hr  Anomalies caused by redundancy E.g., employee name may be spelled Didar Ahmed, Dedar Ahmed, Diader Ahmad or D. Ahmed

19 Conversion to 2NF 1. Starting with 1NF write each of the key components on separate lines, then write the original key on the last line P_No E_No P_No E_No  Each will become key in a new table  Here, original table split into three tables

20 Conversion to 2NF (cont…) 2. Write the dependent attributes after each of the new keys using the dependency diagram P_No  P_Name E_No  E_Name, Job_Class, Chg_Hr P_No E_No  Hrs

21 Three New Tables (2NF) P_NoP_Name 1Hurricane 2Coast 3Satellite E_NoE_NameJob_ClassChg_Hr 101Kamal HossainElec Eng65 102David PolComm Eng60 103Younus MiaAsst Eng55 104Didar AhmedComm Eng60 Project Table Employee Table Assign Table P_NoE_NoHrs 110113 1 10216 1 10419 210115 2 10317 310418 3 10214

22 2NF Definition 1.Table is in 1NF and 2.It includes no partial dependencies (no attribute is dependent on only a portion of the primary key) **Note: Since partial dependencies can exist only if there is a composite key, a table with a single attribute as primary key is automatically in 2NF if it is in 1NF

23 Problem - Transitive Dependency  Note that Chg_Hr is dependent on Job_Class, but neither Chg_Hr nor Job_Class is part of the primary key  This is called transitive dependency A condition in which an attribute is functionally dependent on non-key attributes (another attribute that is not part of the primary key)  Transitive dependency yields data anomalies

24 Conversion to 3NF  Break off the pieces that are identified by the transitive dependency arrows (lower arrows) in the dependency diagram  Store them in a separate table P_No  P_Name E_No  E_Name, Job_Class P_No E_No  Hrs Job_Class  Chg_Hr **Note: Job_Class must be retained in Employee table to establish a link to the newly created Job table

25 New Tables (3NF) P_NoP_Name 1Hurricane 2Coast 3Satellite E_NoE_NameJob_Class 101Kamal HossainElec Eng 102David PolComm Eng 103Younus MiaAsst Eng 104Didar AhmedComm Eng Project Table Employee Table Assign Table P_NoE_NoHrs 110113 1 10216 1 10419 210115 2 10317 310418 3 10214 Job_ClassChg_Hr Elec Eng65 Comm Eng60 Asst Eng55 Job Table

26 3NF Definition 1.Table is in 2NF and 2.It contains no transitive dependencies

27 Problem  Although the four tables are in 3NF, we have a potential problem  The Job_Class is entered for each new employee in the Employee table  For example, too easy to enter Electrical Engr, or EE, or El Eng E_NoE_NameJob_Class 101Kamal HossainElec Eng 102David PolComm Eng 103Younus MiaAsst Eng 104Didar AhmedComm Eng 105Ali AhmedAsst Eng 106Nipa AhmedElec Eng Employee Table

28 New Attribute  Create a Job_Code attribute to serve as primary key in the Job table and as a foreign key in the Employee table

29 New Tables P_NoP_Name 1Hurricane 2Coast 3Satellite E_NoE_NameJob_Code 101Kamal Hossain500 102David Pol501 103Younus Mia502 104Didar Ahmed501 Project Table Employee Table Assign Table P_NoE_NoHrs 110113 1 10216 1 10419 210115 2 10317 310418 3 10214 Job_CodeJob_ClassChg_Hr 500Elec Eng65 501Comm Eng60 502Asst Eng55 Job Table

30 Another Example…

31 The Problem: Keeping Track of a Stack of Invoices

32 Required Table Orders order_id order_date customer_id customer_name customer_address customer_city customer_state item_id item_description item_qty item_price

33 First Normal Form: No Repeating Elements or Groups of Elements  NF1 addresses two issues: 1. A row of data cannot contain repeating groups of similar data (atomicity) 2. Each row of data must have a unique identifier (or Primary Key) Orders order_id (PK) order_date customer_id customer_name customer_address customer_city customer_state item_id (PK) item_description item_qty item_price

34 Second Normal Form: No Partial Dependencies on a Concatenated Key  Here we test each table for partial dependencies on a concatenated key.  This means that for a table that has a concatenated primary key, each column in the table that is not part of the primary key must depend upon the entire concatenated key for its existence.  If any column only depends upon one part of the concatenated key, then we say that the entire table has failed Second Normal Form and we must create another table to rectify the failure.

35 Checking Partial Dependencies Orders order_id (PK) order_date  customer_id ? customer_name ? customer_address ? customer_city ? customer_state ? item_id (PK) item_description  item_qty item_price  Orders order_id (PK) order_date customer_id customer_name customer_address customer_city customer_state item_id (PK) item_description item_qty item_price

36 Second Normal Form: orders order_id (PK) order_date customer_id customer_name customer_address customer_city customer_state items item_id (PK) item_description item_price order_items order_id (PK) item_id (PK) item_qty

37 Third Normal Form: No Dependencies on Non-Key Attributes  Here, we return to the problem of the repeating customer information. As our database now stands, if a customer places more than one order then we have to input all of that customer's contact information again. This is because there are columns in the orders table that rely on "non-key attributes".

38 Third Normal Form: orders order_id (PK) customer_id (FK) order_date items item_id (PK) item_description item_price order_items order_id (PK) item_id (PK) item_qty customers customer_id (PK) customer_name customer_address customer_city customer_state

39 Summary  1NF – Eliminate repeating groups  2NF – Eliminate partial dependencies  3NF – Eliminate transitive dependencies

40 Thanks to All


Download ppt "Lecture – 5 Course Code – MIS4102.  Edgar F. Codd, the inventor of the relational model, introduced the concept of normalization and what we now know."

Similar presentations


Ads by Google