24
1 Normalisation Connolly, Ch. 13

Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

  • Upload
    vutruc

  • View
    226

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

1

Normalisation

Connolly, Ch. 13

Page 2: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

2

2

Overview

• Normalisation– Steps

• 1NF– Removing repeating groups

• 2NF– Partial dependencies

– Removing partial dependencies

• 3NF– Transitive dependencies

– Removing transitive dependencies

Page 3: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

3

3

Normalisation

• “A formal technique for analysing relationsbased on their primary key and functionaldependencies.” [Codd].

• Process– Analyse each relation using a set of rules

– If a relation does meet a rule• Decompose the relation into two or more relations

Page 4: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

4

4

Normalisation Steps

Each step in the process reduces the update anomalies that can occur.

0NF

1NF

2NF

3NF

BCNF

4NF

5NF

Page 5: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

5

5

Unnormalised Form (0NF)

• A 0NF relation may have:– Multivalued attributes

• Some attributes have more than one value

– Composite attributes• Some attributes consist of multiple parts

– Nested relations• Some attributes contain another relation

Page 6: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

6

6

0NF Example

Proj-id, Proj-Start-Date, Location and Weeks-on-Projectcontain multiple values

Page 7: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

7

7

First Normal Form (1NF)

• Definition– “A relation in which the intersection of each row

and column contains one and only one value.”• “No repeating groups”

• A 1NF relation does not contain– Multivalued attributes

– Composite attributes

– Nested relations

Page 8: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

8

8

Converting 0NF to 1NF

• “Remove repeating groups”– Start with a 0NF relation which contains...

• a key that identifies a set of attributes

• and a set of attributes that repeat

– Remove the repeating attributes and place them in aseparate relation

– Include a copy of the original key in the newrelation

Page 9: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

9

9

1NF - Identify the Repeating Group

Key Repeating Group

Page 10: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

10

10

1NF - Remove the Repeating GroupEmp1

EmpProj1

Page 11: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

11

11

1NF Relations

Emp1(emp-no, emp-name, dept, manager)

EmpProj1(emp-no, proj-id, proj-start-date, location, weeks-on-project)

Page 12: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

12

12

Second Normal Form (2NF)

• Definition– “A relation that is in 1NF and every non-primary-

key attribute is fully dependent on the primary key.”• “Remove partial dependencies”

• A 2NF relation is one that– Is in 1NF

– and contains no partial dependencies

Page 13: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

13

13

Partial Dependency on the Key

• An attribute that is dependent on part of the key

(A, B, C, D)

AB → CA → D

D is partially dependent on the key (AB)

Page 14: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

14

14

Converting 1NF to 2NF

• Identify all partial dependencies

• Ignore all relations with a single attributeprimary key

– This relation is in 2NF

• Create a new relation– Remove the partially determined attribute

– Copy part of the primary key

Emp1

Page 15: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

15

15

2NF - Identify Partial Dependencies

EmpProj1

Proj-Start-Date is dependent on part of the key.

Page 16: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

16

16

2NF - Remove Partial Dependency

Proj2

EmpProj2

Create a relation with the proj-start-date attribute and a copy of the proj-id attribute.

Remove the proj-start-dateattribute.

Page 17: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

17

17

2NF Relations

Emp2(emp-no, emp-name, dept, manager)

EmpProj2(emp-no, proj-id, location, weeks-on-project)

Proj2(proj-id, proj-start-date)

Page 18: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

18

18

Third Normal Form (3NF)

• Definition– “A relation that is in 2NF and every non-primary-

key attribute is dependent on the primary key only.”• “Remove transitive dependencies.”

• A 3NF relation is one that– Is in 3NF

– and contains no transitive dependencies

Page 19: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

19

19

Transitive Dependency on the Key

• An attribute that is dependent on an attributeother than the key

(A, B, C, D)

AB → CC → D

D is transitively dependent on the key (AB)through C

Page 20: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

20

20

Converting 2NF to 3NF

• Identify all transitive dependencies

• Ignore all relations with two attributes

• For each transitive dependency– Create a new relation

– Remove the transitively determined attribute

– Copy the determining attribute

Proj2

Page 21: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

21

21

3NF - Identify Transitive Dependencies

Manager is dependent on a non-key attribute.

Emp2

Page 22: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

22

22

3NF - Remove Transitive Dependency

Dept3

Emp3Remove the managerattribute.

Create a relation withthe manager attribute anda copy of the dept attribute.

Page 23: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

23

23

3NF Relations

Emp3(emp-no, emp-name, dept)

Dept3(dept, manager)

EmpProj2(emp-no, proj-id, location, weeks-on-project)

Proj2(proj-id, proj-start-date)

Page 24: Normalisation - smckearney.com · 4 4 Normalisation Steps Each step in the process reduces the update anomalies that can occur. 0NF 1NF 2NF 3NF BCNF 4NF 5NF

24

24

Third Normal Form

Process1NF - Remove repeating groups

2NF - Remove partial dependencies

3NF - Remove transitive dependencies

Emp3

Dept3

Proj3

EmpProj3