CS263 Lecture 20 Revision on Normalisation

LECTURE PLAN
 Purpose of Normalisation

 Redundancy and Data Anomalies
 Repeating Groups  Functional Dependency

 Transitive Dependency
 Stages of Normalisation

Purpose of Normalisation  To avoid redundancy by storing each ‘fact’ within the database only once. To put the data into a form that is more able to accurately accommodate change.    To facilitate the enforcement of data constraints. single valued attributes.. each relation represents one entity) . .no repeating groups. To avoid certain updating ‘anomalies’.  To put data into a form that conforms to relational principles (e.g.

Example: We have the following relation that contains staff and department details: staffNo job SL10 Salesman SA51 Manager DS40 Clerk OS45 Clerk dept 10 20 20 30 dname Sales Accounts Accounts Operations city Stratford Barking Barking Barking Such ‘redundancy’ could lead to the following ‘anomalies’ Insert Anomaly: We can’t insert a dept without inserting a member of staff that works in that department Update Anomaly: We could change the name of the dept that SA51 works in without simultaneously changing the dept that DS40 works in. i.e. the redundant data could be removed without the loss of information.Redundancy and Data Anomalies Redundant data is where we have stored the same ‘information’ more than once. .. Deletion Anomaly: By removing employee SL10 we have removed all information pertaining to the Sales dept.

. 079311122 017111777 079311555 Repeating Groups are not allowed in a relational design.Repeating Groups A repeating group is an attribute (or set of attributes) that can have more than one value for a primary key value. since all attributes have to be ‘atomic’ .e. 018111888. there can only be one value per cell in a table! . Example: We have the following relation that contains staff and department details and a list of telephone contact numbers for each member of staff.i. staffNo job SL10 Salesman SA51 Manager DS40 Clerk OS45 Clerk dept 10 20 20 30 dname Sales Accounts Accounts Operations city Stratford Barking Barking Barking contact number 018111777.

A is called the determinant and B is called the object of the determinant. Example: staffNo job SL10 Salesman SA51 Manager DS40 Clerk OS45 Clerk dept 10 20 20 30 dname Sales Accounts Accounts Operations Functional Dependencies staffNo  job staffNo  dept staffNo  dname dept  dname .Functional Dependency Formal Definition: Attribute B is functionally dependant upon attribute A (or a collection of attributes) if a value of A determines a single value of attribute B at any one time. Formal Notation: A  B This should be read as ‘A determines B’ or ‘B is functionally dependant on A’.

line#)  qty (Order#. Full Functional Dependency: Only of relevance with composite determinants. then such a determinant is termed a composite determinant. This is the situation when it is necessary to use all the attributes of the composite determinant to identify its object uniquely. Example: order# A001 A002 A002 A004 line# 001 001 002 001 qty 10 20 20 15 price 200 400 800 300 Full Functional Dependencies (Order#.Functional Dependency Compound Determinants: If more than one attribute is necessary to determine another attribute in an entity. line#)  price .

Example: student# unit# room grade 9900100 A01 TH224 2 9900010 A01 TH224 14 9901011 A02 JS075 3 9900001 A01 TH224 16 Full Functional Dependencies (student#.Functional Dependency Partial Functional Dependency: This is the situation that exists if it is necessary to only use a subset of the attributes of the composite determinant to identify its object uniquely. unit#)  grade Partial Functional Dependencies unit#  room Repetition of data! .

Transitive Dependency Definition: A transitive dependency exists when there is an intermediate functional dependency. then it can be stated that the following transitive dependency exists: A  B  C Example: staffNo job SL10 Salesman SA51 Manager DS40 Clerk OS45 Clerk dept 10 20 20 30 dname Sales Accounts Accounts Operations Transitive Dependencies staffNo  dept dept  dname staffNo  dept  dname Repetition of data! . Formal Notation: If A  B and B  C.

Normalisation . THE KEY. AND NOTHING BUT THE KEY! .Relational Model In order to comply with the relational model it is necessary to 1) remove repeating groups and 2) avoid redundancy and data anomalies by remoting partial and transitive functional dependencies. Relational Database Design: All attributes in a table must be atomic. THE WHOLE KEY. and solely dependant upon the fully primary key of that table.

Stages of Normalisation Unnormalised (UDF) Remove repeating groups First normal form (1NF) Remove partial dependencies Second normal form (2NF) Remove transitive dependencies Third normal form (3NF) Boyce-Codd normal form (BCNF) Remove remaining functional dependency anomalies Remove multivalued dependencies Fourth normal form (4NF) Remove remaining anomalies Fifth normal form (5NF) .

.. and it suffers from various anomalies..Unnormalised Normal Form (UNF) Definition: A relation is unnormalised when it has not had any normalisation rules applied to it. etc. manual document.. the capturing of attributes to a ‘Universal Relation’ from a screen layout. manual report.e. i. This only tends to occur where the relation has been designed using a ‘bottom-up approach’.

order-total .Unnormalised Normal Form (UNF) ORDER Customer No: Name: Address: 001964 Mark Campbell 1 The House Leytonstone E11 9ZZ Product Description Hook Bolt Spanner Unit Price 5.00 Order Number: Order Date: 00012345 14-Feb-2002 Product Number T5060 PT42 QZE48 Order Quantity 5 10 1 Order Total: Line Total 25. (prod-no.50 20.00 20.00 2.50 20. line-total)*. prod-desc. cust-no. unit-price. cust-add. cust-name.50 ORDER (order-no.00 65. order-date. ord-qty.

order-date. (prod-no.First Normal Form (1NF) Definition: A relation is in 1NF if. cust-no. . line-total)*. unit-price. cust-add. ORDER (order-no. all its underlying attributes contain atomic values only. Name the new entity (appending the number 1 to indicate 1NF) Determine the PK of the new entity Repeat steps until no more repeating groups. order-total Steps from UNF to 1NF:      Remove the outermost repeating group (and any nested repeated groups it may contain) and create a new relation to contain it. prod-desc. Add to this relation a copy of the PK of the relation immediately enclosing it. and only if. ord-qty. cust-name. Remove repeating groups into a new relation A repeating group is shown by a pair of brackets within the relational schema.

line-total) 3. unit-price. order-total (order-no. prod-desc. unit-price. cust-name. ord-qty. order-total (prod-no. prod-desc. cust-name. prod-no. cust-add. Determine the PK of the new entity ORDER-LINE-1 (order-no. cust-no. line-total) . prod-desc. line-total) 4. ord-qty. ORDER-1 (order-no. ord-qty. order-total 1. line-total) 2.Example . prod-no. (rename original to indicate 1NF) ORDER-1 (order-no. order-date.UNF to 1NF ORDER (order-no. unit-price. Remove the outermost repeating group (and any nested repeated groups it may contain) and create a new relation to contain it. (prod-no. Name the new entity (appending the number 1 to indicate 1NF) ORDER-LINE-1 (order-no. cust-add. prod-no. ord-qty. cust-name. cust-no. prod-desc. order-date. ord-qty. prod-desc. unit-price. Add to this relation a copy of the PK of the relation immediately enclosing it. cust-add. line-total)*. cust-no. unit-price. order-date.

it is in 1NF and every non-key attribute is fully dependent on the primary key. Remove partial functional dependencies into a new relation Steps from 1NF to 2NF:  Remove the offending attributes that are only partially functionally dependent on the composite key. and place them in a new relation. and only if. Add to this relation a copy of the attribute(s) which are the determinants of these offending attributes.    Name the new entity (appending the number 2 to indicate 2NF) Rename the original entity (ending with a 2 to indicate 2NF) .Second Normal Form (2NF) Definition: A relation is in 2NF if. These will automatically become the primary key of this new relation.

unit-price. prod-no. Name the new entity (appending the number 2 to indicate 2NF) PRODUCT-2 (prod-no. ORDER-LINE-1 (order-no. Rename the original entity (ending with a 2 to indicate 2NF) ORDER-LINE-2 (order-no. prod-no.Example . line-total) . prod-no.1NF to 2NF ORDER-LINE-1 (order-no. prod-desc. unit-price) 2. These will automatically become the primary key of this new relation. ord-qty. line-total) (prod-desc. ord-qty. prod-desc. ord-qty. unit-price) 4. line-total) (prod-no. Add to this relation a copy of the attribute(s) which determines these offending attributes. ORDER-LINE-1 (order-no. and place them in a new relation. prod-desc. prod-no. line-total) 1. Remove the offending attributes that are only partially functionally dependent on the composite key. unit-price) 3.. ord-qty.

These will automatically become the primary key of this new relation. it is in 2NF and every non-key attribute is non-transitively dependent on the primary key. and only if. and place them in a new relation. Add to this relation a copy of the attribute(s) which are the determinants of these offending attributes. Remove transitive dependencies into a new relation Steps from 2NF to 3NF:  Remove the offending attributes that are transitively dependent on non-key attribute(s).Third Normal Form (3NF) Definition: A relation is in 3NF if. Name the new entity (appending the number 3 to indicate 3NF)    Rename the original entity (ending with a 3 to indicate 3NF) .

cust-add ) 3. order-total 1. Name the new entity (appending the number 3 to indicate 3NF) CUSTOMER-3 (cust-no. and place them in a new relation. order-date. ORDER-2 (order-no. Remove the offending attributes that are transitively dependent on non-key attributes. order-total (cust-no. cust-name. order-date.2NF to 3NF ORDER-2 (order-no. order-date. cust-no. cust-add ) 2. cust-name. cust-add ) 4. cust-no.. cust-name. These will automatically become the primary key of this new relation. cust-add.Example . ORDER-2 (order-no. order-date. Add to this relation a copy of the attribute(s) which determines these offending attributes. order-total . Rename the original entity (ending with a 3 to indicate 3NF) ORDER-3 (order-no. cust-no. cust-no. order-total (cust-name.

order-date. cust-add ) PRODUCT-2 (prod-no.Relations in 3NF ORDER-3 (order-no. prod-no ORDER-LINE . line-total) order-no ORDER places placed by prod-no PRODUCT contains shows belongs to cust-no CUSTOMER part of order-no. order-total CUSTOMER-3 (cust-no. prod-no. cust-no. prod-desc. ord-qty. unit-price) ORDER-LINE-2 (order-no.Example . cust-name.

No more lectures before exam Either Email me (a.browne) with any questions. or come to my office (27 AA 03) at the times that that the CS263 lectures are usually given Good Luck! .

Sign up to vote on this title
UsefulNot useful