26
University of Sunderland COM 220 Lecture Four Slide 1 An Introduction to An Introduction to Relational Data Relational Data Analysis Analysis (Normalisation) (Normalisation)

An Introduction to Relational Data Analysis (Normalisation)

Embed Size (px)

DESCRIPTION

An Introduction to Relational Data Analysis (Normalisation). Relational Data Analysis. Steps in Normalisation 1.Un-normalised form 2.First Normal Form 3.Second Normal Form 4.Third Normal Form. Relational Data Analysis Student Results Table. Relational Data Analysis. - PowerPoint PPT Presentation

Citation preview

Page 1: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 1

An Introduction toAn Introduction toRelational Data AnalysisRelational Data Analysis

(Normalisation)(Normalisation)

Page 2: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 2

Steps in NormalisationSteps in Normalisation1.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 Relational Data AnalysisAnalysis

Page 3: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 3

Relational Data AnalysisRelational Data AnalysisStudent Results TableStudent 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

Page 4: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 4

Relational Data Relational Data AnalysisAnalysis

Possible Entities in SystemPossible Entities in System

• COURSECOURSE

• STUDENTSTUDENT

• TUTORTUTOR

• GRADE?GRADE?

Page 5: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 5

Relational DataRelational Data Analysis Analysis

Unnormalised FormUnnormalised Form

• Table made up of ROWS & Table made up of ROWS & COLUMNSCOLUMNS

• Rows grouped togetherRows grouped together

• write table in unnormalised formwrite table in unnormalised form

• choose unique KEY and underlinechoose unique KEY and underline

Page 6: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 6

Relational Data Relational Data AnalysisAnalysis

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

Page 7: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 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 Relational Data AnalysisAnalysis

Normalisation TableNormalisation Table

Page 8: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 8

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

Relational Data Relational Data AnalysisAnalysis

First Normal FormFirst Normal Form

Page 9: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 9

Relational Data Relational Data AnalysisAnalysis

Course Code enter name of non-repeating group

SYA

COB

PAS

enter values of non-repeating attribute

Page 10: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 10

Relational Data Relational Data AnalysisAnalysis

Course Code Course Title

SYA

COB

PAS

Systems Analysis

COBOL

Pascal

Page 11: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 11

Relational Data Relational Data AnalysisAnalysis

CourseCode

StudentCode

StudentName

Date ofBirth

TutorCode

TutorName

Grade Result

SYASYASYASYASYA

COBCOBCOB

PASPASPASPAS

A2345A7423B3472A3472B9843

A7423A4217B8238

A4217B9843A3393A4247

SmithBarkerGreenHarrisGreen

BarkerMorrisCarter

MorrisGreenWhiteCross

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

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

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

17461746133017461330

152015201520

1520128312831520

JonesJonesJarvisJonesJarvis

HooperHooperHooper

HooperTrotterTrotterHooper

ACDFB

EBC

ABEC

Dist.PassPassFailMerit

FailMeritPass

Dist.MeritFailPass

Page 12: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 12

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 Relational Data AnalysisAnalysis

Normalisation TableNormalisation Table

Page 13: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 13

Relational Data Relational Data AnalysisAnalysis

Normalisation TableNormalisation TableUNF UNF 1NF

2NF 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

Page 14: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 14

Relational Data Relational Data AnalysisAnalysis

Normalisation TableNormalisation TableUNF 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

Page 15: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 15

Relational Data Relational Data AnalysisAnalysis

Normalisation TableNormalisation TableUNF 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

Page 16: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 16

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

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

Relational Data Relational Data AnalysisAnalysis

Second Normal FormSecond Normal Form

Page 17: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 17

Relational Data Relational Data AnalysisAnalysis

What attribute or attributes determine the What attribute or attributes determine the TUTOR CODE?TUTOR CODE?

• Course CodeCourse Code

• Student CodeStudent Code

• Course Code + Student CodeCourse Code + Student Code

Page 18: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 18

Relational Data Relational Data AnalysisAnalysis

Student CodeStudent Code Student Student NameName

Student CodeStudent Code

Tutor CodeTutor Code

Course CodeCourse Code

Page 19: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 19

Relational Data Relational Data AnalysisAnalysis

Student Name

Date of Birth

Course Code Tutor Code

Student Code Tutor Name

Grade

Result

Page 20: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 20

UNF UNF 1NF 2NF3NF 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 Relational Data AnalysisAnalysis

Normalisation Table - 2NFNormalisation Table - 2NF

Page 21: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 21

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 Relational Data AnalysisAnalysis

Normalisation Table - 2NFNormalisation Table - 2NF

Page 22: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 22

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

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

Relational Data Relational Data AnalysisAnalysis

Third Normal FormThird Normal Form

Page 23: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 23

UNF UNF 1NF 2NF3NF

LEVEL

Course Code 1 Course Code Course CodeCourse Code

Course Title 1 Course Title Course TitleCourse TitleStudent Code 2Student Name 2 Course Code Course Code

Course CodeDate of Birth 2 Student Code Student Code

Student CodeTutor Code 2 Student Name Tutor CodeTutor 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 AnalysisRelational Data AnalysisNormalisation Table - 3NFNormalisation Table - 3NF

Page 24: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 24

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 GradeResult 2 Tutor Name Result

Student CodeGrade

Student NameResult Student Code

Date of BirthStudent NameDate of Birth

Tutor Code

Tutor Name

Grade

Result

Relational Data AnalysisRelational Data AnalysisNormalisation Table - 3NF

Foreign key

Page 25: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 25

Relational Data Relational Data AnalysisAnalysis

Summary:Summary:• choose a suitable key from a table of raw datachoose a suitable key from a table of raw data• identify repeating groupsidentify repeating groups• write the data in unnormalised formwrite the data in unnormalised form• convert unnormalised data to first normal formconvert unnormalised data to first normal form• convert first normal form to second normal formconvert first normal form to second normal form• convert second normal form to third normal formconvert second normal form to third normal form

Page 26: An Introduction to Relational Data Analysis (Normalisation)

University of Sunderland COM 220 Lecture Four Slide 26

Further ReadingFurther Reading

• Relational Data Analysis – Lejk & Deeks, 2nd edition, chpt 8

• Next week– NO LECTURE but read slides on DB Admin

• Following week– Building Interactive Forms