Download presentation
Presentation is loading. Please wait.
Published byClare Gordon Modified over 9 years ago
1
Switch off your Mobiles Phones or Change Profile to Silent Mode
2
Normalisation
3
Topics Introduction Why Normalisation Functional Dependency Transitive Dependency Normalisation - Order Example Un-normalised Form First Normal Form Second Normal Form Third Normal Form
4
Introduction Normalisation is to get data into a simple form that truly reflects separate entity types, their attributes and relationships between them to avoid unnecessary duplication of data Starts from pre-documented sets of attributes and tries to group and regroup them without causing data inconsistencies in such a way that Anomalies are avoided
5
Why Normalisation The database design must be efficient (performance-wise). The amount of data should be reduced if possible. The design should be free of update, insertion and deletion anomalies. The design must comply with rules regarding relational databases.
6
Why Normalisation The design has to show pertinent relationship between entities. The design should permit simple retrieval, simplify data maintenance and reduce the need to restructure data.
7
Anomalies Anomalies are undesirable side effects that can occur if relations are not in the proper normal form. Anomalies fall into three categories: Insertion Anomaly Adding new rows forces user to create duplicate data or occurs when we cannot insert a new row into the relation because some or all of the primary key value is not known.
8
Anomalies Update Anomaly Changing data in a row forces changes to other rows because of duplication Update: occurs when we have unnecessary redundancy in the data and we are forced to update several rows. Deletion Anomaly Deleting rows may cause a loss of data that would be needed for other future rows
9
Functional Dependencies (FD) Normalisation is based on the analysis of functional dependence. A Functional Dependency is a particular relationship between two attributes. Attribute B is Functionally Dependent upon attribute A (or a collection of attributes) if a value of A determines a single value of B at any one time. The value of one attribute determines the value of another attribute
10
Functional Dependencies (FD) The notation for this Functional Dependency is: A B This notation is read “A determines B” or “B is Functionally Dependent on A”. A is called the determinant and B is called the object of the determinant. A composite determinant is made up of more than one attribute: X, Y Z
11
Functional Dependencies (FD) Full Functional Dependency (FD) Relevant with composite determinants. If it is necessary to use all the attributes of the composite determinant to identify its object uniquely, we have Full Functional Dependency. Partial Functional Dependency (PFD) Dependency exists if it is necessary to use only a subset of attributes of a composite determinant to identify object uniquely.
12
FD - An Example Student-idActivity CostProficiency 100Squash200A 100Swimming100B 150Swimming100B 175Scuba300L 175Aerobics200I Squash200A Swimming100B FFD = student-id, activity proficiency PFD = activity cost
13
Transitive Dependency (TD) Transitive Dependency exists when there is an intermediate dependency. Assume three attributes A, B and C. Further assume that the following functional dependencies exist: A B, B C Then it can be stated that the following transitive dependency also holds: A B C
14
TD - An Example Student-idAccomodation Fee 100Perkin1100 150Gatehouse1200 200Gatehouse1200 250Perkin1100 300Ingleside1500 FD = student-id accommodation FD = student-id fee FD = accommodation fee TD = student-id accommodation fee
15
An Order Form – Example
16
Steps in Normalisation
17
Step 1: Un-Normalised Form (UNF) All attributes with repeating groups included Step 2: First Normal Form (1NF) Any repeating groups have been removed, so that there is a single value at the intersection of each row and column of the table. Step 3: Second Normal Form (2NF) Any Partial Functional Dependencies have been removed.
18
Steps in Normalisation Step 4: Third Normal Form (3NF) Any Transitive Dependencies have been removed. (N.B. If a relation meets the criteria for 3NF, it also meets criteria for 2NF and 1NF. Most design problems can be avoided if the relations are in 3NF.)
19
Un-normalised Normal Form (UNF) A relation is un-normalised if it has not had any normalisation rules applied to it and if it suffers from various anomalies. Sources of un-normalised data are: Computer Screen Layouts Reports Computer Programs User Manuals
20
Order -no Order- date Cust -no Cust- name Cust- address Prod- no Prod- desc Unit- price Ord- qty Line- total Order -total 005743511-JAN-061489Arthur Smith 1 Lime Avenue Anytown ZZ52 5QA T5060Lock5.0052570.00 005743511-JAN-061489Arthur Smith 1 Lime Avenue Anytown ZZ52 5QA PT42Alarm20.001 70.00 005743511-JAN-061489Arthur Smith 1 Lime Avenue Anytown ZZ52 5QA QZE248Key2.501025.0070.00 Un-normalised Normal Form (UNF)
21
Applying UNF ORDER (order-no, order-date, cust-no, cust-name, cust-address, {prod-no, prod- desc, unit-price, ord-qty, line-total}, order- total) ORDER
22
First Normal Form (1NF) Repeating groups should be removed to a separate entity. 1NF restriction is built into the relational model Advantages of 1NF are simplicity and uniform access.
23
Applying 1NF ORDER (order-no, order-date, cust-no, cust- name, cust-address, {prod-no, prod-desc, unit- price, ord-qty, line-total}, order-total) ORDER-1 (order-no, order-date, cust-no, cust- name, cust-address, order-total) ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total) ORDER ORDER-LINE Contains
24
Second Normal Form (2NF) A relation is in 2NF if It is in 1NF, and All non-key attributes are Fully Functionally Dependent on the Primary Key and not on only a portion of the Primary Key.
25
Second Normal Form (2NF) Attributes that are wholly dependent on only part of composite identifier should be removed to a separate entity. Prohibits situation where each row represents single-valued facts about more than one object. Partial FDs on an identifier should be avoided because they result in data redundancy.
26
Second Normal Form (2NF) Steps to transform into 2NF Identify all Functional Dependencies in 1NF. Make each determinant the Primary Key of a new relation. Place all attributes that depend on a given determinant in the relation with that determinant as non-key attributes.
27
Applying 2NF ORDER-1 (order-no, order-date, cust-no, cust- name, cust-address, order-total) ORDER-LINE-1 (order-no, prod-no, prod-desc, unit-price, ord-qty, line-total) ORDER-2 (order-no, order-date, cust-no, cust- name, cust-address, order-total) ORDER-LINE-2 (order-no, prod-no, ord-qty, line- total) PRODUCT-2 (prod-no, prod-desc, unit-price)
28
Identifying PFDs How are the non-key attributes dependent on the determinants? order-no, prod-no ord-qty, line-total prod-no prod-desc, unit-price order-no
29
Second Normal Form (2NF) Entities with only a single attribute key are already in 2NF: A b, c, d Entities with a composite key may not be in 2NF, as there may be some PDs: X, Y l, m, n
30
Second Normal Form (2NF) A relation that is in First Normal Form will be in Second Normal Form if any one of the following conditions apply: The Primary Key consists of only one attribute (such as the attribute ORDER- NO in ORDER). No non-key attributes exist in the relation. Every non-key attribute is Functionally Dependent on the full set of Primary Key attributes
31
Third Normal Form (3NF) A relation is in 3NF if It is in 2NF, and No Transitive Dependencies. Transitive Dependencies are when A B C. Thus it can be split into A B and B C.
32
Third Normal Form (3NF) Attributes that are wholly dependent upon another attribute should be removed to a separate entity. Like 2NF, but now we consider FDs on non-key attributes only and do not worry about the key. Transitive Dependencies should be avoided because they result in data redundancy.
33
Third Normal Form (3NF) Steps to transform into 3NF Create one relation for each determinant in the Transitive Dependency. Make the determinants the Primary Keys in their respective relations. Include as non-key attributes those attributes that depend on the determinant.
34
Applying 3NF ORDER-2 (order-no, order-date, cust-no, cust-name, cust- address, order-total) ORDER-LINE-2 (order-no, prod-no, ord-qty, line-total) PRODUCT-2 (prod-no, prod-desc, unit-price) ORDER-3 (order-no, order-date, cust-no order-total) ORDER-LINE-3 (order-no, prod-no, ord-qty, line-total) PRODUCT-3 (prod-no, prod-desc, unit-price) CUSTOMER-3 (cust-no, cust-name, cust-address)
35
Third Normal Form (3NF) Entities which are all-key OR have only a single non-key attribute are already in 3NF: A, B A b Entities with more than one non-key attribute may not be in 3NF, as there may be some TDs: X, Y l, m, n X l, m
36
ER Model Representation The final list of 3NF entities can be represented by the following ER model:
37
Eliminating Redundancy
38
Any Questions?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.