15
1 Information Management Centre, Thames Valley University Relational Modelling (Normalisation) Abdisalam Issa-Salwe Faculty of Professional Studies Thames Valley University Week 7 Seminar Information Management Centre, Thames Valley University Company Name Company Number Job Title Job Ref Number Applicant Address Applicant Name Applicant Number 1NF UNF

Week 7 normalisation lecture (last)

Embed Size (px)

Citation preview

Page 1: Week 7 normalisation lecture (last)

1

Information Management Centre, Thames Valley University

Relational Modelling (Normalisation)

Abdisalam Issa-Salwe

Faculty of Professional Studies

Thames Valley University

Week 7 Seminar

Information Management Centre, Thames Valley University

Company Name

Company Number

Job Title

Job Ref Number

Applicant Address

Applicant Name

Applicant Number

1NF UNF

Page 2: Week 7 normalisation lecture (last)

2

Information Management Centre, Thames Valley University

UNF – 1NF

Applicant

Applicant Number

Applicant Name

Applicant Address

Job Ref Number

Job Title

Company Number

Company Name

Information Management Centre, Thames Valley University

Company Name

Company Number

Job Title

Job Ref Number

Applicant Address

Applicant Name

Applicant Number

1NF UNF

Page 3: Week 7 normalisation lecture (last)

3

Information Management Centre, Thames Valley University

UNF: Remove Repeating Groups

Create a new group for the multi-valued attributes

Include the Primary Key attribute from the original group as a Foreign Key in the new group

Choose a key for the new group

Information Management Centre, Thames Valley University

Company Name

Company Number

Job Title Company Name

Job Ref Number Company Number

Job Title

Job Ref Number

Applicant Address Applicant Address

Applicant Name Applicant Name

Applicant Number Applicant Number

1NF UNF

Page 4: Week 7 normalisation lecture (last)

4

Information Management Centre, Thames Valley University

Company Name

Company Number

Job Title Company Name

Job Ref Number Company Number

*Applicant Number Job Title

Job Ref Number

Applicant Address Applicant Address

Applicant Name Applicant Name

Applicant Number Applicant Number

1NF UNF

Information Management Centre, Thames Valley University

Applicant

Applicant's Job

Applicant Number

Applicant Name

Applicant Address

Job Ref Number

Job Title

Company Number

Company Name

Page 5: Week 7 normalisation lecture (last)

5

Information Management Centre, Thames Valley University

Applicant

Applicant's Job

Applicant Number

Applicant Name

Applicant Address

Job Ref Number

Job Title

Company Number

Company Name

*Applicant Number

1NF – 2NF

Information Management Centre, Thames Valley University

1NF – 2NF

Applicant Number

Applicant Name

Applicant Address

*Applicant Number

*Job Ref Number

Applicant

Applicant's Job

Job

Job Reference Number

Job Title

Company Number

Company Name

Page 6: Week 7 normalisation lecture (last)

6

Information Management Centre, Thames Valley University

1NF – 2NF

Applicant Number

Applicant Name

Applicant Address

*Applicant Number

*Job Ref Number

Applicant

Applicant's Job

Job

Job Reference Number

Job Title

Company Number

Company Name

Information Management Centre, Thames Valley University

1NF to 2NF: Remove Partial Dependencies

Partial dependency only arises where we have a compound key

It describes the situation where there is a functional dependency between one part of the key and some non-key attribute e.g. Job Reference Number determines Job

Title, Company Number and Company Name

Page 7: Week 7 normalisation lecture (last)

7

Information Management Centre, Thames Valley University

Partial Dependency example

Job Reference Number determines Job Title

Job Ref Number

Applicant Number

Job Title

J24 A1001 Trainee SA

J24 A1002 Trainee SA

J99 A1002 IT Manager

Information Management Centre, Thames Valley University

1NF to 2NF: Remove Partial Dependencies (cont…)

Create a new group for all the partially dependent data items

The Primary Key of the new group will be the attribute(s) that the partially dependent data items depended on

The key of the original group does not change

Page 8: Week 7 normalisation lecture (last)

8

Information Management Centre, Thames Valley University

2NF

Company Name

Company Number

Job Title

Job Ref Number

*Applicant Number

1NF

Information Management Centre, Thames Valley University

2NF to 3NF: Remove Transitive Dependencies

A transitive dependency arises where there is a dependency between two data items neither of which is a candidate key for the data group in question

e.g. Company Number determines Company Name

Page 9: Week 7 normalisation lecture (last)

9

Information Management Centre, Thames Valley University

Remove the data items that depend on the non-candidate key attribute

The attribute that determines them is the Primary Key of the new group

Leave behind a copy of this attribute as a Foreign Key

2NF to 3NF: Remove Transitive Dependencies (cont…)

Information Management Centre, Thames Valley University

2NF – 3NF

Company Name

Company Number

Company Name

Company Number

Job Title Job Title

Job Reference Number Job Reference Number

3NF 2NF

Page 10: Week 7 normalisation lecture (last)

10

Information Management Centre, Thames Valley University

2NF – 3NF

2NF 3NF

Job Reference Number Job Reference Number

Job Title Job Title

Company Number

Company Name

Company Number

Company Name

Information Management Centre, Thames Valley University

2NF – 3NF

2NF 3NF

Job Reference Number Job Reference Number

Job Title Job Title

Company Number *Company Number

Company Name

Company Number

Company Name

Page 11: Week 7 normalisation lecture (last)

11

Information Management Centre, Thames Valley University

2NF – 3NF

Applicant

Applicant's Job

Job

Job Ref Number

Title

Company Number

Company Name

Information Management Centre, Thames Valley University

2NF – 3NF

Applicant

Applicant's Job

Job

Company Company Number

Company Name

Job Ref Number

Title

*Company Number

Page 12: Week 7 normalisation lecture (last)

12

Information Management Centre, Thames Valley University

Functional Dependency

A Function in mathematics is a relation between two domains A,B such that

for every a in A there is exactly one corresponding b in B

e.g. A and B both real numbers:

square(x) is a function

but

sqrt(x) is not a function

sqrt(4) = (-2,2) since -2*-2 = 4 as well as 2*2=4

this is an example of a non-functional dependency

Information Management Centre, Thames Valley University

Mnemonic

“the key, the whole key and nothing but the key”

2NF “the key” : non-key fields depend on the key

“the whole key”: non-key fields depend fully on the key

3NF “nothing but the key”: non-key fields are not

dependent on each other

Page 13: Week 7 normalisation lecture (last)

13

Information Management Centre, Thames Valley University

Unnormalised Entity

Begin with an entity from

the logical data model

Information Management Centre, Thames Valley University

First Normal Form (1NF)

Look for repeating groups of attributes and

remove them into separate entities

Page 14: Week 7 normalisation lecture (last)

14

Information Management Centre, Thames Valley University

Second Normal Form (2NF)

If an entity has a concatenated identifier, look for attributes that depend only on part of the identifier. If found, remove to new entity.

Information Management Centre, Thames Valley University

Third Normal Form (3NF)

Look for attributes that depend only on another non-identifying attribute.

If found, remove to new entity. Also remove any calculated attributes.

Page 15: Week 7 normalisation lecture (last)

15

Information Management Centre, Thames Valley University

Potential anomalies

UPDATE the price per session of facility 1

now different rates for squash courts - suspect business rule is same rate for all facilities for a ‘sport’

ADD a new tennis court

must also ensure the same rate is used as for other tennis courts

DELETE facility 11

lose the rate per session for skittles

Information Management Centre, Thames Valley University

Summary: Data modelling

Data modelling answers the question:

What data exists and what is the most efficient way of organising it?

Data Modelling is the analysis of data in organisations,

departments, branches, etc.

It captures all the data uses,

It organises it into an efficient structure.

Data modelling = the construction of a model of the data

requirements of the organisation.

Data requirements are more stable that processing

requirements.

There are two techniques:

1. Entity-relationship modelling - a top down approach.

2. Normalisation - a bottom up approach.