35
1 An Introduction to An Introduction to Relational Data Analysis Relational Data Analysis (Normalisation) (Normalisation)

1 An Introduction to Relational Data Analysis (Normalisation)

  • View
    221

  • Download
    2

Embed Size (px)

Citation preview

1

An Introduction toAn Introduction to

Relational Data AnalysisRelational Data Analysis(Normalisation)(Normalisation)

2

Steps in Steps in NormalisationNormalisation

1.1. Un-normalised formUn-normalised form

2.2. First Normal FormFirst Normal Form

3.3. Second Normal FormSecond Normal Form

4.4. Third Normal FormThird Normal Form

Relational Data AnalysisRelational Data Analysis

3

Relational Data AnalysisStudent Results Table

CourseCode

CourseTitle

StudentCode

StudentName

Date ofBirth

TutorCode

TutorName

Grade Result

SYA SystemsAnalysis

A2345A7423B3472A3472B9843

SmithBarkerGreenHarrisGreen

20/08/6903/04/5923/02/7017/07/6910/11/68

17461746133017461330

JonesJonesJarvisJonesJarvis

ACDFB

Dist.PassPassFailMerit

COB COBOL A7423A4217B8238

BarkerMorrisCarter

03/04/6917/01/6809/12/69

152015201520

HooperHooperHooper

EBC

FailMeritPass

PAS Pascal A4217B9843A3393A4247

MorrisGreenWhiteCross

17/01/6810/11/6830/09/6925/12/69

1520128312831520

HooperTrotterTrotterHooper

ABEC

Dist.MeritFailPass

4

Relational Data AnalysisRelational Data Analysis

Possible Entities in SystemPossible Entities in System

• COURSECOURSE• STUDENTSTUDENT• TUTORTUTOR• GRADE?GRADE?

5

Relational Data AnalysisRelational Data Analysis

Unnormalised Form:Unnormalised Form:• Table made up of ROWS and Table made up of ROWS and

COLUMNSCOLUMNS• Rows grouped togetherRows grouped together• Write table in unnormalised Write table in unnormalised

formform• Choose unique KEY and Choose unique KEY and

underlineunderline

6

Relational Data Analysis

Data AttributesData Attributes• Student CodeStudent Code• Student NameStudent Name• Date of BirthDate of Birth

• All REPEAT for a given value of COURSE CODE

• Tutor CodeTutor Code• Tutor NameTutor Name• GradeGrade• ResultResult

7

UNF UNF 1NF 2NF 3NFLEVEL

Course Code 1Course Title 1

Student Code 2Student Name 2Date of Birth 2Tutor Code 2Tutor Name 2Grade 2Result 2

Relational Data AnalysisRelational Data Analysis

Normalisation TableNormalisation Table

8

• Any relation is in First Normal Any relation is in First Normal Form when it contains no Form when it contains no repeating groups of datarepeating groups of data

Relational Data AnalysisRelational Data Analysis

First Normal FormFirst Normal Form

9

UNF UNF 1NF 2NF 3NFLEVEL

Course Code 1 Course Code Course Title 1 Course Title

Student Code 2Student Name 2 Course CodeDate of Birth 2 Student CodeTutor Code 2 Student NameTutor Name 2 Date of BirthGrade 2 Tutor CodeResult 2 Tutor Name

GradeResult

Relational Data AnalysisRelational Data Analysis

Normalisation TableNormalisation Table

10

Relational Data AnalysisRelational Data Analysis

Normalisation TableNormalisation Table

UNF UNF 1NF2NF 3NF LEVEL

Course Code 1 Course CodeCourse Title 1 Course Title

Student Code 2Student Name 2Date of Birth 2Tutor Code 2 Course CodeTutor Name 2 Student CodeGrade 2 Student NameResult 2 Date of Birth

Tutor CodeTutor NameGradeResult

11

Relational Data AnalysisRelational Data Analysis

Normalisation TableNormalisation Table

UNF UNF 1NF 2NF3NF

LEVEL

Course Code 1 Course CodeCourse Title 1 Course Title

Student Code 2Student Name 2Date of Birth 2Tutor Code 2 Course CodeTutor Name 2 Student CodeGrade 2 Student NameResult 2 Date of Birth

Tutor CodeTutor NameGradeResult

12

Relational Data AnalysisRelational Data Analysis

Normalisation TableNormalisation Table

UNF UNF 1NF 2NF3NF

LEVEL

Course Code 1 Course CodeCourse Title 1 Course Title

Student Code 2Student Name 2Date of Birth 2Tutor Code 2 Course CodeTutor Name 2 Student CodeGrade 2 Student NameResult 2 Date of Birth

Tutor CodeTutor NameGradeResult

13

• Any relation already in 1NF is also Any relation already in 1NF is also in 2NF if EITHER the key is a single in 2NF if EITHER the key is a single attribute OR the non-key items attribute OR the non-key items are fully dependent on the WHOLE are fully dependent on the WHOLE keykey

• In Second Normal Form, you In Second Normal Form, you remove data items which depend remove data items which depend on only part of a keyon only part of a key

Relational Data Analysis

Second Normal FormSecond Normal Form

14

Relational Data Analysis

Student CodeStudent Code Student Student NameName

Student CodeStudent Code

Tutor CodeTutor Code

Course CodeCourse Code

15

Relational Data Analysis

Student NameDate of Birth

Course Code Tutor CodeStudent Code Tutor

NameGradeResult

16

UNF UNF 1NF2NF 3NF LEVEL

Course Code 1 Course Code Course CodeCourse Title 1 Course Title Course Title

Student Code 2Student Name 2 Course Code Course

CodeDate of Birth 2 Student Code

Student CodeTutor Code 2 Student Name Tutor CodeTutor Name 2 Date of Birth

Tutor NameGrade 2 Tutor Code GradeResult 2 Tutor Name Result

GradeResult

Student CodeStudent

NameDate of

Birth

Relational Data Analysis

Normalisation Table - 2NFNormalisation Table - 2NF

17

• Any relation in 2NF is also 3NF if Any relation in 2NF is also 3NF if all non-key attributes are all non-key attributes are independent of all other non-key independent of all other non-key attributes and all key attributes attributes and all key attributes are independent of all the other are independent of all the other key attributeskey attributes

• In Third Normal Form, you remove In Third Normal Form, you remove any attributes which are not any attributes which are not directly dependentdirectly dependent upon the keyupon the key

Relational Data Analysis

Third Normal FormThird Normal Form

18

UNF UNF 1NF 2NF3NF

LEVEL

Course Code 1 Course Code Course CodeCourse Code

Course Title 1 Course Title Course TitleCourse Title

Student Code 2Student Name 2 Course Code Course Code

Course CodeDate of Birth 2 Student Code Student

Code Student CodeTutor Code 2 Student Name Tutor Code

Tutor CodeTutor Name 2 Date of Birth Tutor

Name GradeGrade 2 Tutor Code Grade

Result 2 Tutor Name ResultStudent Code

GradeStudent Name

Result Student Code Date of Birth

Student NameDate of Birth

Tutor Code

Tutor Name

Grade

Result

Relational Data AnalysisNormalisation Table - 3NFNormalisation Table - 3NF

19

UNF UNF 1NF2NF 3NF

LEVEL

Course Code 1 Course Code Course CodeCourse Code

Course Title 1 Course Title Course TitleCourse Title

Student Code 2Student Name 2 Course Code Course Code

Course CodeDate of Birth 2 Student Code Student

Code Student CodeTutor Code 2 Student Name Tutor Code

*Tutor CodeTutor Name 2 Date of Birth Tutor

Name *GradeGrade 2 Tutor Code Grade

Result 2 Tutor Name ResultStudent Code

GradeStudent Name

Result Student CodeDate of Birth

Student NameDate of Birth

Tutor Code

Tutor Name

Grade

Result

Relational Data AnalysisNormalisation Table - 3NF

Foreign key

20

Relational Data Analysis

Summary:Summary:• Choose a suitable key from a table of raw Choose a suitable key from a table of raw

datadata• Identify repeating groupsIdentify repeating groups• Write the data in unnormalised formWrite the data in unnormalised form• Convert unnormalised data to first Convert unnormalised data to first

normal formnormal form• Convert first normal form to second Convert first normal form to second

normal formnormal form• Convert second normal form to third Convert second normal form to third

normal formnormal form

21

Normalisation

Constructing a Data Model from 3NF

22

UNF UNF 1NF2NF 3NF

LEVEL

Course Code 1 Course Code Course CodeCourse Code

Course Title 1 Course Title Course TitleCourse Title

Student Code 2Student Name 2 Course Code Course Code

Course CodeDate of Birth 2 Student Code Student

Code Student CodeTutor Code 2 Student Name Tutor Code

*Tutor CodeTutor Name 2 Date of Birth Tutor

Name *GradeGrade 2 Tutor Code Grade

Result 2 Tutor Name ResultStudent Code

GradeStudent Name

Result Student CodeDate of Birth

Student NameDate of Birth

Tutor Code

Tutor Name

Grade

Result

Normalisation Table - 3NF

Foreign key

23

Student Results RelationsCOURSE

Course CodeCourse Title

COURSE-STUDENT

Course CodeStudent CodeTutor CodeGrade

STUDENT

Student CodeStudent NameDate of Birth

TUTOR

Tutor CodeTutor Name

GRADE

GradeResult

24

Create an entity type for each data relation e.g.

COURSE

Course Code

COURSE-STUDENT

Course CodeStudent Code*Tutor Code*Grade

25

Make compound key relations into details

refers to master / detail relationshipCOURSE STUDENT

COURSE-STUDENT

Course CodeStudent Code

Course Code Student Code

26

Make relations with foreign keys into detailsCOURSE STUDENT

COURSE-STUDENT

Course CodeStudent Code*Tutor Code*Grade

Course Code Student Code

TUTOR GRADETutor Code Grade

27

Redrawn Entity Model

COURSE STUDENT

COURSE-STUDENT

Course CodeStudent Code*Tutor Code*Grade

Course Code Student Code

TUTOR GRADETutor Code Grade

28

Example 2

COURSE

Course CodeCourse Title

COURSE-STUDENT

Course CodeStudent Code

STUDENT

Student CodeStudent Name

RESULT

Student Code(Course Code)(Ass. Number)Ass. Mark

ASSIGNMENT

(Course Code)(Ass. Number)Ass. Subject

29

Rule 1

Create an entity type for each data relation e.g.

COURSE

Course Code

COURSE-STUDENT

Course CodeStudent Code

30

Rule 2

Mark the qualifying elements of hierarchic keys as a foreign key

• hierarchic key in this exampleASSIGNMENT

*(Course Code) (Ass. Number)

Rule 2

Note: ENTIRE key must be hierarchic

31

Rule 3

Check that all masters of compound key relations are

presentThis example has two compound

keys• one made from simple key and

hierarchic key• one made from two simple

keys

COURSE-STUDENT

Course CodeStudent Code

RESULT

Student Code(Course Code)(Ass. Number)

32

Rule 4

Make compound key relations into details

refers to master / detail relationshipCOURSE STUDENT

COURSE-STUDENT

Course CodeStudent Code

Course Code Student Code

33

Rule 4Make compound key relations into

details refers to master / detail

relationshipCOURSE STUDENT

COURSE-STUDENT

Course CodeStudent Code

Course Code Student Code

ASSIGNMENT

RESULT

*(Course Code) (Ass. Number)

Student Code(Course Code)(Ass. Number)

Rule 4 Rule 4Rule 4

34

Rule 5

COURSE

STUDENT

COURSE-STUDENTCourse Code

Student Code

Course Code

Student Code

ASSIGNMENT

RESULT

*(Course Code) (Ass. Number)

Student Code(Course Code)(Ass. Number)

Make relations with foreign keys into details

Rule 5

Rule 2

35

3NF Model

COURSE

STUDENT

COURSE-STUDENT

Course CodeStudent Code

Course Code

Student Code

ASSIGNMENT

RESULT

*(Course Code) (Ass. Number)

Student Code(Course Code)(Ass. Number)

Rule 4 Rule 4Rule 4

Rule 5

Rule 2