Download presentation
Presentation is loading. Please wait.
Published byBernadette Lisa Goodwin Modified over 9 years ago
1
Modelling Techniques - Normalisation Description and exemplification of normalisation.Description and exemplification of normalisation. Creation of un-normalised form (UNF) from complex source document(s).Creation of un-normalised form (UNF) from complex source document(s). First normal form:First normal form: –identifying repeating groups, dealing with repeating groups, problems with first normal form (1NF). Second normal form:Second normal form: –functional dependency, problems with second normal form (2NF). Third normal form:Third normal form: –transitive dependency.
2
Normalisation Normalisation aims to remove data redundancy by applying rules in a series of stages, splitting tables within the existing database system and creating relationships between them to ensure that the structure of the database is efficient and data can be accurately manipulated. The structure produced by the normalisation process will be efficient and allow data to be easily updated and maintained. The structure will contain a number of related tables. Each table will have a number of properties: – –The order of the rows in not significant. The rows do not have to be in any particular order and the order may be changed without loss of information. – –The order of the columns is not significant. The columns of a table may be interchanged without loss of information. – –Each row/column intersection contains only one value. – –Each row of the table must be capable of being uniquely identified by a single attribute or a combination of attributes. This attribute or combination of attributes is referred to as the primary key. The primary key cannot contain a null value. – –Each table is linked to at least one other table in the system. The attribute used to link one table to another is called the foreign key.
3
Normalisation Normalisation is a complex mathematical process. To fully understand it, you must first understand the terms repeating group and functional dependency. A repeating group is defined to be a set of two or more multi-valued attributes. For example: – –a single book title may have several authors – –a single pupil may sit exams in several different subjects A functional dependency occurs when one attribute - or combination of attributes - in a relation uniquely determines another attribute.
4
Normalisation When carried out correctly, the normalisation process identifies an efficient structure for the entities in the database system. Normalisation ensures that: – –all redundant data has been removed from the entities This means that all duplicated values have been removed and the database system will require less memory. As a result, any processing carried out on the data will be more efficient. – –all data anomalies have been removed This means that whenever the data is to be updated, it only needs to be updated once. New details can be added to and deleted from individual tables without affecting details held in other tables. This ensures that the data is easy to maintain. All entities created as a result of applying the normalisation process are said to demonstrate entity integrity. Foreign keys are used to relate one entity to another. Whenever this happens, the normalised data must demonstrate referential integrity
5
Working example – car rental client_nbrclient_nbr client_nameclient_name client_addressclient_address client_telephoneclient_telephone client_faxclient_fax contact_personcontact_person shipment_nbrshipment_nbr insurance_refinsurance_ref fromfrom toto datedate timetime van_regvan_reg modelmodel makemake capacitycapacity fuel_typefuel_type rental_costrental_cost Look through the list and identify any potential primary keysLook through the list and identify any potential primary keys –client_nbr –shipment_nbr –insurance_ref –van_reg Sometimes when the list comes from more than 1 source document there will be repeating attributes. If there are any they must be removed!Sometimes when the list comes from more than 1 source document there will be repeating attributes. If there are any they must be removed! Choose 1 PK and turn into UNF.Choose 1 PK and turn into UNF.
6
UNF The most important step in creating UNF is analysing the source document or documents (there may be more than one) in order to determine the attributes that are held in the system. If there is more than one source document, it is best to deal with each document separately. Once the attributes in each document have been fully normalised, any links between the sets of normalised tables can be easily identified. This process of linking sets of normalised entities to create a single normalised system is called consolidation. Creating UNF for a single document – –analyse the details held on the source document carefully – –write down a single list of all attributes that appear in the source document – –identify any attributes that can be calculated using other values in the system – –identify the primary key of the un-normalised attributes by underlining it – –identify any repeating groups of data – –name each UNF entity
7
Working example – car rental CLIENT(client_nbrCLIENT(client_nbr client_nameclient_name client_addressclient_address client_telephoneclient_telephone client_faxclient_fax contact_personcontact_person shipment_nbr shipment_nbr insurance_ref insurance_ref from from to to date date time time van_reg van_reg model model make make capacity capacity fuel_type fuel_type rental_cost) rental_cost) This is unnormalised form (UNF).This is unnormalised form (UNF). We have selected our first Entity – client.We have selected our first Entity – client. We can see the attributes that will belong to client and the attributes that would be repeating because they belong in other entities. E.g the client may have more than 1 van take a shipment to them, the client may have more than 1 shipment. These are repeating values.We can see the attributes that will belong to client and the attributes that would be repeating because they belong in other entities. E.g the client may have more than 1 van take a shipment to them, the client may have more than 1 shipment. These are repeating values.
8
1NF The most important step in creating 1NF is the removal of repeating groups of data. By removing repeating groups of data to form separate entities, we reduce data duplication and therefore make the database more efficient. We also remove any values that can be calculated since this again reduces the storage that is necessary and improves the efficiency of the database.
9
1NF Creating 1NF from UNF – –Write out list of attributes in main entity leaving behind any repeating group(s). Also leave out any attributes that can be calculated. – –Create a separate list of attributes for each repeating group. If one set of attributes repeats inside another set, take the outer set of repeating attributes out from the main entity before removing the inner set of repeating attributes. – –Identify a primary key of each new entity by underlining it. – –Copy the primary key of any outer repeating group into the inner repeating group and asterisk it to indicate that this is the foreign key link to the outer repeating group. – –Take a copy of the primary key of the main entity into each new entity and asterisk it to indicate that it is also a foreign key. – –Decide whether or not this foreign key is needed to form a unique value for the primary key of each new entity. – –Name each 1NF entity.
10
Working example – car rental CLIENT(client_nbrCLIENT(client_nbr client_nameclient_nameclient_addressclient_telephone client_faxclient_fax contact_person)contact_person) REMOVAL(REMOVAL( shipment_nbrshipment_nbr insurance_refinsurance_ref fromfrom toto datedate van_regvan_reg modelmodel makemake capacitycapacity fuel_typefuel_type rental_costrental_cost *client_nbr) To choose the primary key of removal ask the question – Is there an attribute that is unique for each client? The answer is yes – shipment_nbr. So this is our PK.To choose the primary key of removal ask the question – Is there an attribute that is unique for each client? The answer is yes – shipment_nbr. So this is our PK. A foreign key must be added to the removal so that a relationship can be created so we add client_nbr as a foreign key.A foreign key must be added to the removal so that a relationship can be created so we add client_nbr as a foreign key. This is 1 st Normal Form (1NF).This is 1 st Normal Form (1NF).
11
2NF The most important step in creating 2NF is the removal of non-key attributes that only depend on part of the primary key. This means that 2NF is only of concern when the primary key of an entity is a compound primary key - in other words, it is composed of two or more attributes. Where the primary key is a single attribute, the entity is already in second normal form. Attributes that depend on part of the primary key are said to have a partial dependency on the primary key. The aim of 2NF is to create entities where every non-key attribute is fully dependent on the primary key of the entity.
12
2NF Creating 2NF from 1NF – –Copy out any entities with a single primary key. These entities are already in 2NF – –In entities with a compound primary key, identify any attributes that depend on part of the compound primary. – –Write out the attributes in the entity with the compound primary key, leaving behind any attributes that have a partial dependency. – –Mark the part of the primary key that the caused the partial dependency with an asterisk. This is a foreign key link to the new entity you are about to create. – –Create a new entity by copying the part of the compound primary key that is responsible for the partial dependency. This becomes the primary key of the new entity. – –Add the non-key attributes that have a partial dependency to the new entity. – –Name each 2NF entity.
13
Working example – car rental CLIENT(client_nbrCLIENT(client_nbr client_nameclient_nameclient_addressclient_telephone client_faxclient_faxcontact_person) Shipment(shipment_nbrShipment(shipment_nbrinsurance_ref) Removal (*shipment_nbrRemoval (*shipment_nbrfromtodatetimevan_regmodel makemakecapacityfuel_typerental_cost *client_nbr) Client is in 2NF because the attributes all rely on client_nbr and no other key.Client is in 2NF because the attributes all rely on client_nbr and no other key. Next we look at the attributes in removal:Next we look at the attributes in removal: –According to Removal we have a compound key (made up of >1 PK). –Is there any attribute(s) in removal that does not use the compound key only 1 of the keys (either the PK or FK)? Yes insurance_ref. We do not need to know the client_nbr to get the insurance_ref we only need the shipment_nbr. So we give shipment_nbr and insurance_ref its’ own entity.So we give shipment_nbr and insurance_ref its’ own entity. This is 2NF.This is 2NF.
14
3NF The most important step in creating 3NF is the removal of non-key attributes that depend on other non-key attributes. Non-key attributes that depend on other non-key attributes are said to have transitive dependency. Creating 3NF from 2NF – –Write out a list of all attributes in any entities that have one or less non-key attributes. These are already in 3NF. – –Examine other entities carefully in order to identify transitive dependencies. – –Write out the attributes in any entity found to have a transitive dependency, leaving behind any non-key attributes that have a transitive dependency. – –Mark the non-key attribute that is responsible for the transitive dependency with an asterisk to indicate a foreign key. – –Copy this attribute and create new entity. Underline the attribute to indicate that the attribute is the primary key. – –Add the non-attributes involved in the transitive dependency into this new entity. – –Name each 3NF entity.
15
Working example – car rental CLIENT(client_nbrCLIENT(client_nbr client_nameclient_nameclient_addressclient_telephoneclient_faxcontact_person) Shipment(shipment_nbrShipment(shipment_nbrinsurance_ref) Removal (*shipment_nbrRemoval (*shipment_nbrfromto datedate timetime *van_reg*van_reg *client_nbr) VAN (van_regVAN (van_reg modelmodel makemake capacitycapacity fuel_typefuel_type rental_cost)rental_cost) A relation is in 3NF if all the columns depend on the primary key and not on any other column:A relation is in 3NF if all the columns depend on the primary key and not on any other column: –Client is in 3NF –Shipment is in 3NF –Removal is not because the details of a van are repeated everytime the van is used for removal but from, to, date and time are a history and depend on the client and shipment. –The details for van rely on the van_reg, not on shipment_nbr and client_nbr. So the entity VAN is created and the van attributes stored here. –Still one problem we need to know which van is used for which removal so van_reg is in removal as a FK. This is 3NF.This is 3NF.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.