Sie sind auf Seite 1von 32

Database and Web Database

Systems
CT014-3-2

Normalization II

Topic & Lesson Structure

How to undertake process of


normalization.
How to identify most commonly used
normal forms, namely 1NF, 2NF, 3NF.

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 2 (of 21)

Learning Outcomes
By the end of this lesson you should be
able to:
Demonstrate how to undertake process of
normalization.
Demonstrate how to identify the most commonly
used normal forms namely 1NF, 2NF, 3NF.

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 3 (of 21)

Keywords
1NF a relation is in 1NF if there are no
repeating groups in the relation.
2NF a relation is in 2NF if it is in 1NF and
there are no partial dependencies on the
primary key.
3NF a relation is in 3NF if it is in 2 NF
and there are no transitive dependencies.
CT014-3-2 Database and Web Database Systems

Normalization II

Slide 4 (of 21)

The Process of Normalization


Formal technique for analyzing a relation based on
its primary key and functional dependencies
between its attributes.
Often executed as a series of steps. Each step
corresponds to a specific normal form, which has
known properties.
As normalization proceeds, relations become
progressively more restricted (stronger) in format
and also less vulnerable to update anomalies.
CT014-3-2 Database and Web Database Systems

Normalization II

Slide 5 (of 21)

Relationship between Normal Forms

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 6 (of 21)

Unnormalized Form (UNF)


A table that contains one or more repeating
groups.
To create an unnormalized table:
transform data from information source (e.g.
form) into table format with columns and rows.

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 7 (of 21)

First Normal Form (1NF)


A relation in which intersection of each row
and column contains one and only one
value.

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 8 (of 21)

UNF to 1NF
Nominate an attribute or group of
attributes to act as the key for the
unnormalized table.
Identify repeating group(s) in
unnormalized table which repeats for the
key attribute(s).

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 9 (of 21)

UNF to 1NF
Remove repeating group by:
entering appropriate data into the empty
columns of rows containing repeating data
(flattening the table).

Or by
placing repeating data along with copy of the
original key attribute(s) into a separate
relation.

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 10 (of 21)

Second Normal Form (2NF)


Based on concept of full functional dependency:
A and B are attributes of a relation,
B is fully dependent on A if B is functionally
dependent on A but not on any proper subset
of A.
2NF - A relation that is in 1NF and every nonprimary-key attribute is fully functionally
dependent on the primary key.
CT014-3-2 Database and Web Database Systems

Normalization II

Slide 11 (of 21)

1NF to 2NF
Identify primary key for the 1NF relation.
Identify functional dependencies in the
relation.
If partial dependencies exist on the primary
key remove them by placing them in a new
relation along with copy of their
determinant.
CT014-3-2 Database and Web Database Systems

Normalization II

Slide 12 (of 21)

Third Normal Form (3NF)


Based on concept of transitive dependency:
A, B and C are attributes of a relation such that if A
B and B C,
then C is transitively dependent on A through B.
(Provided that A is not functionally dependent on B or
C).

3NF - A relation that is in 1NF and 2NF and in


which no non-primary-key attribute is transitively
dependent on the primary key.
CT014-3-2 Database and Web Database Systems

Normalization II

Slide 13 (of 21)

2NF to 3NF
Identify the primary key in the 2NF relation.
Identify functional dependencies in the relation.
If transitive dependencies exist on the primary
key remove them by placing them in a new
relation along with copy of their determinant.

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 14 (of 21)

General Definitions of 2NF and 3NF


Second normal form (2NF)
A relation that is in 1NF and every nonprimary-key attribute is fully functionally
dependent on any candidate key.

Third normal form (3NF)


A relation that is in 1NF and 2NF and in which
no non-primary-key attribute is transitively
dependent on any candidate key.
CT014-3-2 Database and Web Database Systems

Normalization II

Slide 15 (of 21)

Review of Normalization (UNF to 3NF)

Source: Connolly & Begg

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 16 (of 21)

Review of Normalization (UNF to 3NF)

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 17 (of 21)

Review of Normalization (UNF to 3NF)

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 18 (of 21)

Exercise
Convert the following data into 3NF.
Clearly indicate all functional dependencies.
Proj.
Num

Project
Name

Employee Employee Job


Number Name
Class

Chg/
Hour

Hurricane 101
102
104

John
David
Anne

Elect.Eng
65
Comm.Tech 60
Comm.Tech 60

Coast

101
103

John
June

Elect.Eng
Biol.Eng

Satellite

104
102

Anne
David

Comm.Tech 60
Comm.Tech 60

CT014-3-2 Database and Web Database Systems

Normalization II

65
55

Hours
Billed

Total
Charge

13
16
19
Subtotals
15
17
Subtotals
18
14
Subtotals

845
960
1140
2945
975
935
1910
1080
840
1920

Total

6775

Slide 19 (of 21)

Exercise (contd)
1.
2.
3.

Ignore derived columns/values.


Flatten the table.
Identify an appropriate primary key.

ProjNum

ProjName

Enumber

Ename

JobClass

ChgHr

HrsBilled

Hurricane

101

John

Elect. Eng.

65

13

Hurricane

102

David

Comm.Tech

60

16

Hurricane

104

Anne

Comm.Tech

60

19

Coast

101

John

Elect. Eng

65

15

Coast

103

June

Biol. Eng

55

17

Satellite

104

Anne

Comm. Tech

60

18

Satellite

102

David

Comm. Tech

60

14

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 19 (of 21)

Exercise (contd)
UNF
Billing(ProjNum, ProjName, (Enumber,
Ename, JobClass, ChgHr, HrsBilled))
1NF (Flatten table)
Billing2(ProjNum, Enumber, ProjName,
Ename, JobClass, ChgHr, HrsBilled)

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 20 (of 21)

Exercise (contd)
1NF (Flatten table)
Billing2(ProjNum, Enumber, ProjName, Ename,
JobClass, ChgHr, HrsBilled)
Functional Dependencies
ProjNum ProjName (partial dep.)
Enumber Ename, JobClass, ChgHr (partial dep.)
JobClass ChgHr (transitive dep.)

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 20 (of 21)

Exercise (contd)
2NF (Remove partial dependencies)
Project(ProjNum, ProjName)
EmpJob(Enumber, Ename, JobClass,
ChgHr)
Billing3(ProjNum, Enumber, HrsBilled)

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 20 (of 21)

Exercise (contd)
3NF (Remove transitive dependencies)
Job(JobClass, ChgHr)
Emp (Enumber, Ename, JobClass)
Project(ProjNum, ProjName)
Billing3(ProjNum, Enumber, HrsBilled)

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 20 (of 21)

Exercise (2nd approach)


UNF
Billing(ProjNum, ProjName, (Enumber, Ename, JobClass, ChgHr,
HrsBilled))

1NF (Remove repeating group)


Project(ProjNum, ProjName)
Billing2(ProjNum, Enumber, Ename, JobClass, ChgHr, HrsBilled)
Functional Dependencies
Enumber Ename, JobClass, ChgHr (partial dep.)
JobClass ChgHr (transitive dep.)
CT014-3-2 Database and Web Database Systems

Normalization II

Slide 20 (of 21)

Exercise ( 2nd approach contd)


2NF (Remove partial dependencies)
Project(ProjNum, ProjName)
EmpJob(Enumber, Ename, JobClass,
ChgHr)
Billing3(ProjNum, Enumber, HrsBilled)

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 20 (of 21)

Exercise (2nd approach contd)


3NF (Remove transitive dependencies)
Job(JobClass, ChgHr)
Emp (Enumber, Ename, JobClass)
Project(ProjNum, ProjName)
Billing3(ProjNum, Enumber, HrsBilled)

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 20 (of 21)

UNF
Billing(ProjNum, ProjName, (Enumber, Ename, JobClass, ChgHr,
HrsBilled))
1NF (Flatten table)

1NF (Remove repeating group)

Billing2(ProjNum, Enumber,
ProjName, Ename, JobClass, ChgHr,
HrsBilled)

Project(ProjNum, ProjName)
Billing2(ProjNum, Enumber, Ename,
JobClass, ChgHr, HrsBilled)

Functional Dependencies
ProjNum ProjName (partial dep.)
Enumber Ename, JobClass, ChgHr
(partial dep.)
JobClass ChgHr (transitive dep.)

Functional Dependencies
Enumber Ename, JobClass, ChgHr
(partial dep.)
JobClass ChgHr (transitive dep.)

CT014-3-2 Database and Web Database Systems

Normalization II

Comparison (contd)

2NF(First method)

2NF (Second method)

Project(ProjNum, ProjName)
EmpJob(Enumber, Ename, JobClass,
ChgHr)
Billing3(ProjNum, Enumber,
HrsBilled)

Project(ProjNum, ProjName)
EmpJob(Enumber, Ename, JobClass,
ChgHr)
Billing3(ProjNum, Enumber,
HrsBilled)

CT014-3-2 Database and Web Database Systems

Normalization II

Comparison (contd)

3NF(First method)

3NF (Second method)

Job(JobClass, ChgHr)
Emp (Enumber, Ename, JobClass)
Project(ProjNum, ProjName)
Billing3(ProjNum, Enumber,
HrsBilled)

Job(JobClass, ChgHr)
Emp (Enumber, Ename, JobClass)
Project(ProjNum, ProjName)
Billing3(ProjNum, Enumber,
HrsBilled)

CT014-3-2 Database and Web Database Systems

Normalization II

Summary
Definitions for 1NF, 2NF and 3NF.
Converting relations into 3NF.

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 20 (of 21)

Next Session
SQL DDL.

CT014-3-2 Database and Web Database Systems

Normalization II

Slide 21 (of 21)

Das könnte Ihnen auch gefallen