Database Technologies Madalina CROITORU croitoru@lirmm.fr IUT Montpellier
Part 5 NORMAL FORMS AND NORMALISATION
Database design In the database design one can follow a bottom up approach or a top down approach (most well known is the ER modelling) Normalisation is a obligatory step in the design can be used in both cases In the following we will only focus on the normalisation for the top down approach, as a validation technique for the created tables
Normalisation Normalisation is a technique for producing a set of relations with desirable properties, given the data requirements of the enterprise: Minimal number of attributes necessary for the requirements Attributes with a close logical relationship (also called functional dependencies) are found within the same relation Minimal redundancy attributes represented only once with the exception of forgein keys Why normalise: Easy to maintain the data: updates are achieved with a minimal number of operations thus reducing the opportunities for data inconsistency occuring the database Easy to access the data Less space on the computer
Functional dependencies Functional dependency: describe the relationship between attributes. Attribute A is dependent on attribute B (A-> B) if every value of A is associated with exactly one value of B. Example: StaffNo functionally determines position (for a specific staffno we can determine its position). Their relationship is 1:1 for each staffno there is only one position. The converse is not true. The relationship between position and StaffNo is 1:* - there are several staff numbers associated with a given position. When determining functional dependencies it is important to distinguish between the values held at a certain point in time and the set of all possible values (the functional dependency is a property of the relational schema or the property of this particular instance of the relational schema).
Full functional dependency A full functional dependency indicates that if A and B are attributes of a relation, B is fully dependent on A if B is functionally dependent on A but not on any proper subset of A. Example: staffno, sname -> branchno is a functional dependency because each value of (staffno, sname) is associated with a single value of branchno. A full dependency is the following: staffno- >branchno. The functional dependencies we will use for normalisation satisfy: 1. They hold for all time 2. They have minimal number of attributes to maintain the dependency (full functional) 3. There is a one to one relationship between attributes on the left and those of the right hand side (conversely it could be either 1:1 or 1:*).
Normal forms In this course we will focus on: First Normal Form Second Normal Form Third Normal Form There are other normal forms (BCNF, 4NF, 5NF and Higher Normal Forms) not addressed for lack of time. Please check the course reference book for further details.
First normal form A relation is in 1NF if the intersection of each row and column contain one and exactly one value To obtain a 1NF relation one must identify the cells that contain more than one value The cells are flatten: we create new rows that contain each of the information in the cells These relations might contain a lot of redundancy (subject to insertion anomalies) and thus a second normal form is needed.
Second normal form A relation that is in second normal norm is in first normal form and every non primary key attribute is fully functional on the primary key. The normalisation from 1 st normal form relations to 2 nd normal forms relations involves the removal of partial dependencies. If a partial dependency exists we remove the partially dependent attributes from the relation by placing them in a new relation along with a copy of their determinant
2 nd NF - example We identify the functional dependencies of ClientRental: clientno, propertyno->rentstart, rentfinish clientno->cname propertyno->paddress, rent, ownerno, oname ownerno->oname ClientNo, rentstart->propertyno, paddress, rentfinish, rent, ownerno, oname propertyno, rentstart->clientno, cname, rentfinish Non primary ket attributes are removed along with the copy of the part of the primary key they are fully functionally dependent. This results in the creation of three tables.
Third normal form A relation is in third normal form if it is in first and second normal form and every no non-primary key attribute is transitively dependent on the primary key. The normalisation of 2 nd NF relations to 3 rd NF involves the removal of transitive dependencies. If a transitive dependency exists we remove the transitively dependent attribute from the relation by placing the attributes in a new relation along with a copy of the determinant.
rd 3 NF - example PropertyOwner: all the non primary key attributes are functionally dependent on the primary key with the exception of oname which is transitively dependent on the ownerno. We thus create two new relations: PropertyforRent and Owner.
Exercises The following lists samples dentist / patient appointment data. A patient is given an appointment at a specific time and date with a dentist located at a particular hospital (surgery). On each day of patient appointments a dentist is allocated to a specific hospital for that day. Identify the functional dependencies. Describe the normalisation process. Identify the primary, alternate and forgein keys for the 3NF relations.
Exercises A company FastCabs provides taxi service to their clients. Their sample data is illustrated below. Assume that a taxi driver is assigned to a single taxi, but a taxi can be assigned to one or more drivers. Identify the functional dependencies of the table below Apply normalisation to 3NF and check your result if conform to below Explain how the original table can be recreated through relational joins between primary and foreign keys columns of the tables in 3NF.