topic5 normalizationpart2 aug14

32
Database and Web Database Systems CT014-3-2 Normalization II

Upload: aiyas-aboobakar

Post on 15-Jan-2016

244 views

Category:

Documents


0 download

DESCRIPTION

APU CT014!3!2 DWDS

TRANSCRIPT

Page 1: Topic5 NormalizationPART2 Aug14

Database and Web Database Systems

CT014-3-2

Normalization II

Page 2: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Topic & Lesson Structure

• How to undertake process of normalization.

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

Slide 2 (of 21)

Page 3: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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.

Slide 3 (of 21)

Page 4: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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.

Slide 4 (of 21)

Page 5: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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.

Slide 5 (of 21)

Page 6: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Relationship between Normal Forms

Slide 6 (of 21)

Page 7: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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.

Slide 7 (of 21)

Page 8: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

First Normal Form (1NF)

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

Slide 8 (of 21)

Page 9: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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).

Slide 9 (of 21)

Page 10: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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.

Slide 10 (of 21)

Page 11: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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 non-primary-key attribute is fully functionally dependent on the primary key.

Slide 11 (of 21)

Page 12: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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.

Slide 12 (of 21)

Page 13: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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.

Slide 13 (of 21)

Page 14: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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.

Slide 14 (of 21)

Page 15: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

General Definitions of 2NF and 3NF

• Second normal form (2NF)– A relation that is in 1NF and every non-

primary-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.

Slide 15 (of 21)

Page 16: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Review of Normalization (UNF to 3NF)

Slide 16 (of 21)

Source: Connolly & Begg

Page 17: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Review of Normalization (UNF to 3NF)

Slide 17 (of 21)

Page 18: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Review of Normalization (UNF to 3NF)

Slide 18 (of 21)

Page 19: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Exercise

Proj. Num

Project Name

Employee Number

Employee Name

Job Class

Chg/ Hour

Hours Billed

Total Charge

1 Hurricane 101 102 104

John David Anne

Elect.Eng Comm.Tech Comm.Tech

65 60 60

13 16 19

845 960 1140

Subtotals 2945 2 Coast 101

103 John June

Elect.Eng Biol.Eng

65 55

15 17

975 935

Subtotals 1910 3 Satellite 104

102 Anne David

Comm.Tech Comm.Tech

60 60

18 14

1080 840

Subtotals Total

1920 6775

Slide 19 (of 21)

Convert the following data into 3NF.

Clearly indicate all functional dependencies.

Page 20: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Exercise (cont’d)

Slide 19 (of 21)

1. Ignore derived columns/values.

2. Flatten the table.

3. Identify an appropriate primary key.

ProjNum ProjName Enumber Ename JobClass ChgHr HrsBilled

1 Hurricane 101 John Elect. Eng. 65 13

1 Hurricane 102 David Comm.Tech 60 16

1 Hurricane 104 Anne Comm.Tech 60 19

2 Coast 101 John Elect. Eng 65 15

2 Coast 103 June Biol. Eng 55 17

3 Satellite 104 Anne Comm. Tech 60 18

3 Satellite 102 David Comm. Tech 60 14

Page 21: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Exercise (cont’d)

Slide 20 (of 21)

UNF

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

1NF (Flatten table)

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

Page 22: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Exercise (cont’d)

Slide 20 (of 21)

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.)

Page 23: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Exercise (cont’d)

Slide 20 (of 21)

2NF (Remove partial dependencies)

Project(ProjNum, ProjName)

EmpJob(Enumber, Ename, JobClass, ChgHr)

Billing3(ProjNum, Enumber, HrsBilled)

Page 24: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Exercise (cont’d)

Slide 20 (of 21)

3NF (Remove transitive dependencies)

Job(JobClass, ChgHr)

Emp (Enumber, Ename, JobClass)

Project(ProjNum, ProjName)

Billing3(ProjNum, Enumber, HrsBilled)

Page 25: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Exercise (2nd approach)

Slide 20 (of 21)

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.)

Page 26: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Exercise ( 2nd approach cont’d)

Slide 20 (of 21)

2NF (Remove partial dependencies)

Project(ProjNum, ProjName)

EmpJob(Enumber, Ename, JobClass, ChgHr)

Billing3(ProjNum, Enumber, HrsBilled)

Page 27: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Exercise (2nd approach cont’d)

Slide 20 (of 21)

3NF (Remove transitive dependencies)

Job(JobClass, ChgHr)

Emp (Enumber, Ename, JobClass)

Project(ProjNum, ProjName)

Billing3(ProjNum, Enumber, HrsBilled)

Page 28: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

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

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.)

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.)

Page 29: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

2NF(First method)

Project(ProjNum, ProjName)

EmpJob(Enumber, Ename, JobClass, ChgHr)

Billing3(ProjNum, Enumber, HrsBilled)

2NF (Second method)

Project(ProjNum, ProjName)

EmpJob(Enumber, Ename, JobClass, ChgHr)

Billing3(ProjNum, Enumber, HrsBilled)

Comparison (cont’d)

Page 30: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

3NF(First method)

Job(JobClass, ChgHr)

Emp (Enumber, Ename, JobClass)

Project(ProjNum, ProjName)

Billing3(ProjNum, Enumber, HrsBilled)

3NF (Second method)

Job(JobClass, ChgHr)

Emp (Enumber, Ename, JobClass)

Project(ProjNum, ProjName)

Billing3(ProjNum, Enumber, HrsBilled)

Comparison (cont’d)

Page 31: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Summary

• Definitions for 1NF, 2NF and 3NF.

• Converting relations into 3NF.

Slide 20 (of 21)

Page 32: Topic5 NormalizationPART2 Aug14

CT014-3-2 Database and Web Database Systems Normalization II

Next Session

• SQL – DDL.

Slide 21 (of 21)