A normalisation example

Содержание

Слайд 2

Take the following table. StudentID is the primary key.

Is it 1NF?

Take the following table. StudentID is the primary key. Is it 1NF?

Слайд 3

No. There are repeating groups (subject, subjectcost, grade)

How can you make it

No. There are repeating groups (subject, subjectcost, grade) How can you make it 1NF?
1NF?

Слайд 4

Create new rows so each cell contains only one value

But now look

Create new rows so each cell contains only one value But now
– is the studentID primary key still valid?

Слайд 5

No – the studentID no longer uniquely identifies each row

You now need

No – the studentID no longer uniquely identifies each row You now
to declare studentID and subject together to uniquely identify each row.
So the new key is StudentID and Subject.

Слайд 6

So. We now have 1NF.

Is it 2NF?

So. We now have 1NF. Is it 2NF?

Слайд 7

Studentname and address are dependent on studentID (which is part of the

Studentname and address are dependent on studentID (which is part of the
key) This is good.

But they are not dependent on Subject (the other part of the key)

Слайд 8

And 2NF requires…

All non-key fields are dependent on the ENTIRE key (studentID

And 2NF requires… All non-key fields are dependent on the ENTIRE key (studentID + subject)
+ subject)

Слайд 9

So it’s not 2NF

How can we fix it?

So it’s not 2NF How can we fix it?

Слайд 10

Make new tables

Make a new table for each primary key field
Give each

Make new tables Make a new table for each primary key field
new table its own primary key
Move columns from the original table to the new table that matches their primary key…

Слайд 11

Step 1

STUDENT TABLE (key = StudentID)

Step 1 STUDENT TABLE (key = StudentID)

Слайд 12

Step 2

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

Step 2 STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key = Subject)

Слайд 13

Step 3

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE (key

Step 3 STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key = Subject)
= StudentID+Subject)

Слайд 14

Step 3

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE (key

Step 3 STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key = Subject)
= StudentID+Subject)

Слайд 15

Step 4 - relationships

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS

Step 4 - relationships STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key
TABLE (key = StudentID+Subject)

Слайд 16

Step 4 - cardinality

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS

Step 4 - cardinality STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key
TABLE (key = StudentID+Subject)

1

Each student can only appear ONCE in the student table

Слайд 17

Step 4 - cardinality

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS

Step 4 - cardinality STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key
TABLE (key = StudentID+Subject)

1

1

Each subject can only appear ONCE in the subjects table

Слайд 18

Step 4 - cardinality

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS

Step 4 - cardinality STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key
TABLE (key = StudentID+Subject)

1

1

8

A subject can be listed MANY times in the results table (for different students)

Слайд 19

Step 4 - cardinality

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS

Step 4 - cardinality STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key
TABLE (key = StudentID+Subject)

1

1

8

8

A student can be listed MANY times in the results table (for different subjects)

Слайд 20

A 2NF check

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE

A 2NF check STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key =
(key = StudentID+Subject)

1

1

8

8

SubjectCost is only dependent on the primary key,
Subject

Слайд 21

A 2NF check

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE

A 2NF check STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key =
(key = StudentID+Subject)

1

1

8

8

Grade is only dependent on the primary key (studentID + subject)

Слайд 22

A 2NF check

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE

A 2NF check STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key =
(key = StudentID+Subject)

1

1

8

8

Name, Address are only dependent on the primary key
(StudentID)

Слайд 23

But is it 3NF?

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS

But is it 3NF? STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key
TABLE (key = StudentID+Subject)

1

1

8

8

So it is 2NF!

Слайд 24

A 3NF check

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE

A 3NF check STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key =
(key = StudentID+Subject)

1

1

8

8

Oh oh…
What?

Слайд 25

A 3NF check

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE

A 3NF check STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key =
(key = StudentID+Subject)

1

1

8

8

HouseName is dependent on both StudentID + HouseColour

Слайд 26

A 3NF check

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE

A 3NF check STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key =
(key = StudentID+Subject)

1

1

8

8

Or HouseColour is dependent on both StudentID + HouseName

Слайд 27

A 3NF check

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE

A 3NF check STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key =
(key = StudentID+Subject)

1

1

8

8

But either way,
non-key fields are dependent on MORE THAN THE PRIMARY KEY (studentID)

Слайд 28

A 3NF check

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE

A 3NF check STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key =
(key = StudentID+Subject)

1

1

8

8

And 3NF says that non-key fields must depend on nothing but the key

Слайд 29

A 3NF check

STUDENT TABLE (key = StudentID)

SUBJECTS TABLE (key = Subject)

RESULTS TABLE

A 3NF check STUDENT TABLE (key = StudentID) SUBJECTS TABLE (key =
(key = StudentID+Subject)

1

1

8

8

WHAT DO WE DO?

Слайд 30

Again, carve off the offending fields

SUBJECTS TABLE (key = Subject)

RESULTS TABLE (key

Again, carve off the offending fields SUBJECTS TABLE (key = Subject) RESULTS
= StudentID+Subject)

1

1

8

8

Слайд 31

A 3NF fix

SUBJECTS TABLE (key = Subject)

RESULTS TABLE (key = StudentID+Subject)

1

1

8

8

A 3NF fix SUBJECTS TABLE (key = Subject) RESULTS TABLE (key =

Слайд 32

A 3NF fix

SUBJECTS TABLE (key = Subject)

RESULTS TABLE (key = StudentID+Subject)

1

1

8

8

1

8

A 3NF fix SUBJECTS TABLE (key = Subject) RESULTS TABLE (key =

Слайд 33

A 3NF win!

Or…

A 3NF win! Or…

Слайд 34

The Reveal

Before…

After…

RESULTS TABLE (key = StudentID+Subject)

1

1

8

8

1

8

SUBJECTS TABLE (key = Subject)

The Reveal Before… After… RESULTS TABLE (key = StudentID+Subject) 1 1 8
Имя файла: A-normalisation-example.pptx
Количество просмотров: 122
Количество скачиваний: 0