Top Banner
Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4 th edition, 2004, Chapter 10 Additional resources: presentation prepared by Prof Steven A. Demurjian, Sr (http://www.engr.uconn.edu/~steve/courses.html)
75

Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Jan 14, 2016

Download

Documents

Eunice Farmer
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Copyright © 2004 Pearson Education, Inc.

Functional Dependencies & DB

Normalization

The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4th edition, 2004, Chapter 10

Additional resources: presentation prepared by Prof Steven A. Demurjian, Sr (http://www.engr.uconn.edu/~steve/courses.html)

Page 2: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-2

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Chapter Outline1 Informal Design Guidelines for Relational

Databases1.1Semantics of the Relation Attributes1.2 Redundant Information in Tuples and Update Anomalies1.3 Null Values in Tuples1.4 Spurious Tuples

2 Functional Dependencies (FDs)2.1 Definition of FD2.2 Inference Rules for FDs2.3 Equivalence of Sets of FDs

Page 3: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-3

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Chapter Outline(contd.)

3 Normal Forms Based on Primary Keys3.1 Normalization of Relations 3.2 Practical Use of Normal Forms 3.3 Definitions of Keys and Attributes Participating in Keys 3.4 First Normal Form3.5 Second Normal Form3.6 Third Normal Form

Page 4: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-4

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Design ProcessConceptual

Design

ConceptualSchema

(ER Model)

LogicalDesign

Logical Schema(Relational Model)

Analysisof Schema

Step 2: NormalizationAnalyzing the Schema fromPerformance/Efficiency Perspectivesto arrive at “Optimal” Schema

Normalized Schema

Page 5: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-5

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

1. Informal Design Guidelines for

Relational Databases (1)

What is relational database design?The grouping of attributes to form "good" relation schemas

 Two levels of relation schemasThe logical "user view" levelThe storage "base relation" level

 Design is concerned mainly with base relations

 What are the criteria for "good" base relations? 

Page 6: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-6

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Informal Design Guidelines for Relational Databases (2)

We first discuss informal guidelines for good relational design

Then we discuss formal concepts of functional dependencies and normal forms- 1NF (First Normal Form)- 2NF (Second Normal Form)- 3NF (Third Normal Form)

Additional types of dependencies, further normal forms, relational design algorithms by synthesis are discussed in Chapter 11

Page 7: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-7

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

1.1 Semantics of the Relation

Attributes GUIDELINE 1: Informally, each tuple in a relation should represent one entity or relationship instance. (Applies to individual relations and their attributes).

Attributes of different entities (EMPLOYEEs, DEPARTMENTs, PROJECTs) should not be mixed in the same relation

Only foreign keys should be used to refer to other entities  Entity and relationship attributes should be kept apart as

much as possible.

Bottom Line: Design a schema that can be explained easily relation by relation. The semantics of attributes should be easy to interpret.

Page 8: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-8

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Figure 10.1 A simplified COMPANY relational database

schema

Note: The above figure is now called Figure 10.1 in Edition 4

Page 9: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-9

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

1.2 Redundant Information in

Tuples and Update Anomalies Mixing attributes of multiple entities

may cause problemsInformation is stored redundantly

wasting storageProblems with update anomalies

Insertion anomaliesDeletion anomaliesModification anomalies

Page 10: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-10

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

EXAMPLE OF AN UPDATE ANOMALY (1)

Consider the relation:EMP_PROJ ( Emp#, Proj#, Ename, Pname,

No_hours)

 Update Anomaly: Changing the

name of project number P1 from “Billing” to “Customer-Accounting” may cause this update to be made for all 100 employees working on project P1.

Page 11: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-11

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

EXAMPLE OF AN UPDATE ANOMALY (2)

Insert Anomaly: Cannot insert a project unless an employee is assigned to .

Inversely - Cannot insert an employee unless an he/she is assigned to a project.

 Delete Anomaly: When a project is deleted, it will result in deleting all the employees who work on that project. Alternately, if an employee is the sole employee on a project, deleting that employee would result in deleting the corresponding project.

Page 12: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-12

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Figure 10.3 Two relation schemas suffering from update anomalies

Note: The above figure is now called Figure 10.3 in Edition 4

Page 13: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-13

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Figure 10.4 Example States for EMP_DEPT and EMP_PROJ

Note: The above figure is now called Figure 10.4 in Edition 4

Page 14: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-14

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Guideline to Redundant Information in Tuples and Update

Anomalies

GUIDELINE 2: Design a schema that does not suffer from the insertion, deletion and update anomalies. If there are any present, then note them so that applications can be made to take them into account

Page 15: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-15

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

1.3 Null Values in Tuples

GUIDELINE 3: Relations should be designed such that their tuples will have as few NULL values as possible Attributes that are NULL frequently could be placed in separate relations (with the primary key) Reasons for nulls:

attribute not applicable or invalidattribute value unknown (may exist)value known to exist, but unavailable

Page 16: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-16

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

1.4 Information Loss & Spurious

Tuples

Bad designs for a relational database may result in erroneous results for certain JOIN operations

The "lossless join" property is used to guarantee meaningful results for join operations

Page 17: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-17

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Information Loss & Spurious Tuples

We’ve had Guidelines for: One Concept/Relation, Avoiding Update Anomalies, Null Values

Two Other “Related” Concerns Can Arise First, in Decomposing (Splitting) a Relation Apart,

we May “Lose” InformationSecond, in Attempting to Reassemble Two or

More Relations into One (via a Join), Spurious Tuples may Result

A Spurious Tuple “Wasn’t” Present Originally and Makes No Sense - Didn’t Exist and its Existence is Inconsistency

Page 18: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-18

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Suppose Split EMP_PROJ

Page 19: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-19

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

What are Semantics of Split?

EMP_LOCS Means the Employee ENAME Works on Some Project at PLOCATION

EMP_PROJ1 Means the Employee Identified by SSN Works HOURS per Week on Project Identified by PNAME, PNUMBER, PLOCATION

Page 20: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-20

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Recall EMP_PROJ

Page 21: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-21

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

What are Tuples After Split?

Page 22: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-22

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

What is the Issue?Suppose EMP_PROJ1 and EMP_LOCS used in

Place of EMP_PROJThe Split is Legitimate if we Can Recover

the Information Originally in EMP_PROJHow could you Recover the Information?

Natural Join on EMP_PROJ1 and EMP_LOCSWhat would be the Result?

Note: “*’ed” Entries are Spurious TuplesWe do not Obtain the “Correct” InformationWe have Conducted a “Lossy”

Decomposition

Page 23: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-23

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

What Happens When we Join?

What do “*”ed Tuples Represent?

Page 24: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-24

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Guideline 4 GUIDELINE 4:

The relations should be designed to satisfy the lossless join condition.

No spurious tuples should be generated by doing a natural-join of any relations.

There are 2 important properties of decompositions

(a) non-additive or losslessness of the corresponding join

(b) preservation of the functional dependencies. Property (a) is extremely important and cannot be

sacrificed. Property (b) is less stringent and may be

sacrificed. (See Chapter 11).

Page 25: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-25

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

R = (A, B, C) S = (D, C)

b2b2b4

c1c1c2

A B C

c1c2c2c3

d1d2d4d5

D C

a1a2a3a3

a1a2a3

b2b2b4b4

c1c1c2c2

d1d1d2d4

A B C D

RS(A, B, C, D)

lost info of (d5, c3) after join R & S

Guideline 4: Lost Information

A First Example of Lost InformationWhat is Lost in the Join of R and S?

Page 26: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-26

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Guideline 4: Spurious Tuples

A Second Example of Spurious TuplesWhat are Spurious in the Join of R1and

R2?

a1a2a3a4

b1b2b1b2

c1c2c1c2

d1d1d2d3

A B C D

R(A, B, C, D) R1(B, D)

B C

b1b2b1b2

d1d1d2d3

D

d1d1d2d3

A

a1a2a3a4

R2(A, D)

a1a2a1a2a3a4

b1b1b2b2b1b2

c1c2c2c2c1c2

d1d1d1d1d2d3

A B C D

R1 and R2 Join

Page 27: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-27

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

2.1 Functional Dependencies

(1) Functional dependencies (FDs) are used

to specify formal measures of the "goodness" of relational designs

FDs and keys are used to define normal forms for relations

FDs are constraints that are derived from the meaning and interrelationships of the data attributes

A set of attributes X functionally determines a set of attributes Y if the value of X determines a unique value for Y

Page 28: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-28

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Functional Dependencies (2)

X -> Y holds if whenever two tuples have the same value for X, they must have the same value for Y

For any two tuples t1 and t2 in any relation instance r(R): If t1[X]=t2[X], then t1[Y]=t2[Y]

X -> Y in R specifies a constraint on all relation instances r(R)

Denoted by X YX is Called the Left Hand Side of FD Y is Called the Right Hand Side of FD

Read as X Functionally Determines Y in R

Page 29: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-29

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Examples of FD constraints

(1)

social security number determines employee nameSSN -> ENAME

project number determines project name and locationPNUMBER -> {PNAME, PLOCATION}

employee ssn & project number determines the hours per week that the employee works on the project{SSN, PNUMBER} -> HOURS

Page 30: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-30

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Examples of FD constraints (2)

An FD is a property of the attributes in the schema R

The constraint must hold on every relation instance r(R)

If K is a key of R, then K functionally determines all attributes in R (since we never have two distinct tuples with t1[K]=t2[K])

Page 31: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-31

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Example of FDs

{S#, CN} Grade, S# DNAME, DNAME DHead.

STUDENT_DEPT (S#, DName, DHead, CN, Grade)

FDs over STUDENT_DEPT:

S# DHead CN GradeDNAME

fd1

fd2

fd3

Page 32: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-32

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Example of FDs

SSN ENAMEPNUMBER {PNAME, PLOCATION}{SSN, PNUMBER} HOURS

SSN {ENAME, BDATE, ADDRESS, DNUMBER}DNUMBER {DNAME, DMGRSSN}

Page 33: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-33

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Determining FDs Must Understand the Semantics of Data Based on Schema or

Current/Future Instances What are FDs Below?

TEXT COURSE?COURSE TEXT?

What if I add Row “James, Web Databases, Al-Nour”?

Page 34: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-34

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

2.2 Inference Rules for FDsGiven a set of FDs F, we can Infer Additional

FDs that Hold whenever the FDs in F Hold For Example, Consider:

F = {SSN {EName, BDate, Address, DNumber},

DNumber {DName, DMGRSSN} }What are Additional FDs?

SSN EName SSN BDate SSN SSNSSN Address SSN DNumber

DNumber Dname DNumber DMGRSSN

Page 35: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-35

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Inference RulesArmstrong’s Inference Rules

Derived Inference Rules

1. Reflective (IR1): If X Y, then X Y.

2. Augmentation (IR2): If { X Y} then XZYZ.

3. Transitive (IR3): If { XY, YZ } then X Z.

4. Decomposition: If { XYZ } then X Y.5. Additive (Union): If {XY, XZ } then X YZ.

6. Pseudotransitive: If {XY, WYZ } then W X Z.

Page 36: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-36

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Inference Rules for FDs (3)

Closure of a set F of FDs is the set F+ of all FDs that can be inferred from F

Closure of a set of attributes X with respect to F is the set X + of all attributes that are functionally determined by X

X + can be calculated by repeatedly applying IR1, IR2, IR3 using the FDs in F

Page 37: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-37

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Algorithm 10.1 for ClosureGiven a Set of FDs, Each X on LHS of a FD,

Closure X+ are the Attributes Functionally Determined by XAlgorithm 10.1 Determining X+, Closure of X under F

X+ := X;

repeat

1. oldX+ := X+ ;

2. for each FD Y Z in F do

3. if X+ Y then X+ := X+ Z;

until (X+ = old X+ );

Page 38: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-38

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Applying Algorithm 10.1Let F = {SSN ENAME,

PNUMBER {PNAME, PLOCATION}, {SSN, PNUMBER} HOURS }

{SSN}+ = {SSN, ENAME}{PNUMBER}+ = {PNUMBER, PNAME, PLOCATION } {SSN, PNUMBER}+ = {SSN, PNUMBER, ENAME,

PNAME, PLOCATION, HOURS}For Example: Computer {SSN, PNUMBER}+

Is {SSN, PNUMBER} SSN? Yes - Add in ENAME

Is {SSN, PNUMBER, ENAME} PNUMBER? Yes - Add in PNAME, PLOCATION

Is {SSN, PNUMBER, ENAME, PNAME, PLOCATION} {SSN, PNUMBER}?

Yes - Add in HOURS

Page 39: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-39

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Interpreting Closure SetsWhat Does {SSN}+ = {SSN, ENAME} Equate to?

SSN ENAME, SSN SSN, SSN SSN, ENAMEWhat about {PNUMBER}+ ={PNUMBER,PNAME,PLOCATION}

PNUMBER PNAME

PNUMBER PLOCATION

PNUMBER PNUMBER

PNUMBER {PNAME, PLOCATION}

PNUMBER {PNUMBER, PLOCATION}

PNUMBER {PNAME, PNUMBER}

PNUMBER {PNUMBER, PNAME, PLOCATION}Can you do:{SSN, PNUMBER}+ = {SSN, PNUMBER, ENAME,

PNAME, PLOCATION, HOURS}

Page 40: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-40

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Compute {DNUMBER}+

Is {DNUMBER} SSN ? No - Continue to Next FD

Is {DNUMBER} DNUMBER ? Yes - Add in DNAME, DMGRSSN

{DNUMBER}+ = {DNUMBER, DNAME, DMGRSSN}

FYI: {SSN} + ={SSN, ENAME, BDATE, ADDRESS, DNUMBER, DNAME, DMGRSSN}

Let G = {SSN {ENAME, BDATE, ADDRESS, DNUMBER}, DNUMBER {DNAME, DMGRSSN} }

Page 41: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-41

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Inference Rule PropertiesTheorem 1:

X A1A2... An Holds in a Relation Scheme R if

and only if X Ai Holds for all i = 1, ..., nTheorem 2:

Armstrong's Inference Rules are Sound and Complete

Given a set F of Functional Dependencies:By Sound we mean every FD that we can infer

from F by using Armstrong’s Inference Rules is in F+

By Complete we mean every FD in F+ (that F implies) can be Inferred from F by using Armstrong’s Inference Rules

Page 42: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-42

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

2.3 Equivalence of Sets of FDs E is Covered by F (F is said to cover E),

if Every FD in E is also in F+Two sets of FDs E and F are equivalent

if:Every FD in E can be Inferred from F, andEvery FD in F can be Inferred from E

Hence, F and G are Equivalent if F+=G+

Definition: F covers F if every FD in F can be Inferred from F (i.e., if F+ E+)

E and F are Equivalent if E Covers F and F Covers E

Page 43: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-43

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

3 Normal Forms Based on

Primary Keys

3.1 Normalization of Relations 3.2 Practical Use of Normal Forms 3.3 Definitions of Keys and Attributes

Participating in Keys 3.4 First Normal Form3.5 Second Normal Form3.6 Third Normal Form

Page 44: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-44

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

3.1 Normalization of Relations (1)

Normalization: The process of decomposing unsatisfactory "bad" relations by breaking up their attributes into smaller relations

Normal form: Condition using keys and FDs of a relation to certify whether a relation schema is in a particular normal form

Page 45: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-45

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Normalization of Relations (2)

1NF based on definition of relation2NF, 3NF, BCNF based on keys and FDs of

a relation schema4NF based on keys, multi-valued

dependencies : MVDs; 5NF based on keys, join dependencies : JDs (Chapter 11)

Additional properties may be needed to ensure a good relational design (lossless join, dependency preservation; Chapter 11)

Page 46: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-46

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

A Normal Form is a Condition using Keys and FDs to Certify Whether a Relation Schema meets Criteria Primary keys (1NF, 2NF, 3NF) All Candidate Keys ( 2NF, 3NF, BCNF) Multivalued Dependencies (4NF) Join Dependencies (5NF)

5 NF4NF

3NF

2NF

1NF

What are Normal Form?

Page 47: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-47

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

3.2 Practical Use of Normal Forms

Normalization is carried out in practice so that the resulting designs are of high quality and meet the desirable properties

The practical utility of these normal forms becomes questionable when the constraints on which they are based are hard to understand or to detect

The database designers need not normalize to the highest possible normal form. (usually up to 3NF, BCNF or 4NF)

Denormalization: the process of storing the join of higher normal form relations as a base relation—which is in a lower normal form

Page 48: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-48

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

3.3 Definitions of Keys & Attributes Participating in

Keys (1)

A superkey of a relation schema R = {A1, A2, ...., An} is a set of attributes S subset-of R with the property that no two tuples t1 and t2 in any legal relation state r of R will have t1[S] = t2[S]

A key K is a superkey with the additional property that removal of any attribute from K will cause K not to be a superkey any more.

Page 49: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-49

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Definitions of Keys and Attributes Participating in

Keys (2)

If a relation schema has more than one key, each is called a candidate key. One of the candidate keys is arbitrarily designated to be the primary key, and the others are called secondary keys.

A Prime attribute must be a member of some candidate key

A Nonprime attribute is not a prime attribute—that is, it is not a member of any candidate key.

Page 50: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-50

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

First Normal Form (1NF) All Attributes Must Be Atomic Values:

Only Simple and Indivisible Values in the Domain of Attributes.

Each Attribute in a 1NF Relation is a Single ValueDisallows Composite Attributes, Multivalued

Attributes, and Nested Relations (Non-Atomic)

1NF Relation cannot have an Attribute Value : A Set of Values (Set-Value) A Tuple of Values (Nested Relation)

1NF is a Standard Assumption of Relation DBs

Page 51: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-51

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

One Example of 1NFConsider Following Department RelationWhat is the Inherent Problem?

Page 52: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-52

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

What are Possible Solutions?

Decompose: Move the Attribute DLOCATIONS that Violates 1NF into a Separate Relation DEPT_LOCATIONS(DNUMBER, DLOCATION)

Expand the key to have a Separate Tuple in the DEPARTMENT relation for each location (below)

Introduce DLOC1, DLOC2, DLOC3, if there are Three Maximum Locations

Problems with Each? Best Solution?

Page 53: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-53

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Another 1NF Example - Nested RelationsEMP_PROJ - Table and Tuples

Transition to:

Page 54: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-54

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Second Normal Form (2NF)Second Normal Form Focuses on the Concepts

of Primary Keys and Full Functional Dependencies

Intuitively:A Relation Schema R is in Second Normal Form

(2NF) if Every Non-Prime Attribute A in R is Fully Functionally Dependent on the Primary Key

R can be Decomposed into 2NF Relations via the Process of 2NF Normalization

Successful Process Typically Involves Decomposing R into Two or More Relations

Iteratively Applying to Each Relation in Schema

Page 55: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-55

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Full Functional Dependency

Full FD - Formally:Given R(U) and X, YU. If XY holds, and there exists no such X’ that X’X, and X’Y holds over R, then Y is fully dependent on X, denoted as XY

Full FD- Intuitively: A FD XY where Removal of any Attribute from X means the FD no Longer Holds{SSN, PNUMBER} HOURS is full since Neither

SSN HOURS nor PNUMBER HOURS holdsWhat about in the Following:

f

{S#, CN}Grade

Page 56: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-56

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Partial Functional Dependency

Partial FD - Formally:Given R(U) and X, YU. If XY holds but Y is not fully dependent on X ( XY), then Y is partially functional dependent on X, denoted by XY

Partial FD - Intuitively: Removal of a Attribute from the R.H.S. still Results in a Valid FD{SSN, PNUMBER} ENAME is Partial since

Removing PNUMBER still Results in the Valid FD SSN ENAME

Are Following Full or Partial?

p

{S#, CN}CN, {S#, CN}S#{S#, CN, DNAME}Grade

f

Page 57: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-57

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Second Normal Form (2NF)Formal 2NF Definition

R 2NF iff(i) R 1NF;(ii) all Non-Key Attributes in R are Fully

Functional Dependent on Every Key.Alternative Definition:

R 2NF iff the Attributes are Either a Candidate Key, or Fully Dependent on Every Key.

Reason: Partial Functional Dependencies may cause Update Problems

Page 58: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-58

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

One Example of 2NFConsider the Example Below

STUDENT_DEPT(S#, DName, DHead, CN, Grade)

STUDENT_DEPT 1NF

“{S#, CN} DName, DHead” is a Partial FD which causes Update Anomalies

But STUDENT_DEPT 2NF

S# DHead CN GradeDName

fd1

fd2

fd3

Page 59: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-59

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

One Example of 2NF (Continued)

Insertion Anomalies: No Department Can Be Recorded if it has No

Student Who Enrolls Courses

Deletion Anomalies: Delete the Last Student in a Department will also

Delete the Department

Update Anomalies: Change a Head of a Department must Modify All

Students in that Department Due to Redundancies

STUDENT_DEPT(S#, DName, DHead, CN, Grade)

Page 60: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-60

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

One Example of 2NF (Continued)

Decomposition into 2NF by Separating Course Information from Department Information (Link S#)

S_D(S#, DName, DHead)

DHeadDName

fd2

fd3

S#

S_C(S#, CN, Grade)

fd1

S# CN Grade

Page 61: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-61

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Another Example of 2NFEMP_PROJ is 1NF with Key SSN, PNUMBER

but… SSN ENAME - Means ENAME, a Non-Prime

Attribute, Depends Partially on SSN, PNUMBER, i.e., Depend on Only SSN and not Both

PNUMBER {PNAME, PLOCATION} - Means PNAME, PLOCATION, two Non-Prime Attributes, Depends Partially on SSN, PNUMBER, i.e., Depend on Only PNUMEBER and not Both

Page 62: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-62

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Another Example of 2NFWhat Does Decomposition Below

Accomplish?ENAME Fully Dependent on SSNPNAME, PLOC Fully Dependent on PNUMBER

Result: 2NF for EP1, EP2, and EP3

Page 63: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-63

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Yet Another Example of 2NF

Consider 1NF Lots to Track Building Lots for Towns What is the 2NF Problem?

FD3: COUNTY_NAME TAX_RATE Means TAX_RATE Depends Partially on Candidate Key {PROPERTY_ID#,COUNTY_NAME}

All Other Non-Prime Attributes are Fine

Page 64: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-64

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Yet Another Example of 2NF

What Does Decomposition Below Accomplish?TAX_RATE Fully Dependent on COUNTY_NAME

Result: 2NF for LOTS1 and LOTS2

Page 65: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-65

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Third Normal Form (3NF) Third Normal Form Focuses on the Concepts of

Primary Keys and Transitive Functional Dependencies Intuitively:

A Relation Schema R is in Third Normal Form (3NF) if it is in 2NF and no Non-Prime Attribute A in R is Transitively Dependent on Primary Key

R can be Decomposed into 3NF Relations via the Process of 3NF Normalization

In XY and YZ , with X as the Primary Key, there is only a a problem only if Y is not a candidate key. EMP(SSN, Emp#, Salary), SSN Emp# Salary isn’t Problem Since Emp# is a Candidate Key

Page 66: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-66

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Transitive FDsTransitive FD - Formally:

Given R(U) and X, YU. If XY, YX and YX, YZ, then Z is called transitively functional dependent on X.

Transitive FD - Intuitively: a FD XZ that can be derived from two FDs XY and YZ SSN ENAME is non-transitive Since there is no set of

Attributes X where SSN X and X ENAME

S#DHead

S# DHead CN GradeDNAME

fd1

fd2

fd3

Page 67: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-67

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Third Normal Form (3NF)Formal 3NF Definition

R 3NF iff(i) R 2NF;(ii) No Non-Key Attribute of R is Transitively

Dependent on Every Candidate Key.Alternative Definition:

R 3NF iff for every FD X Y, either X is a superkey, or Y is a key attribute.

Reason: Transitive Functional Dependencies may cause Update Problems

Page 68: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-68

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

One Example of 3NF

STUDENT_DEPT(S#, DName, DHead, CN, Grade) 2NF

S_C(S#, CN, Grade) 2NF

S_D(S#, DName, DHead) 2NF

S_D 3NFS_C 3NF But

“S# DHead” is a Transitive FD in S_D and “DHead” is non-key attribute.

Page 69: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-69

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

One Example of 3NF

S_C(S#, CN, Grade) 2NF

S_D(S#, DName, DHead) 2NF

S_D (S#, DName)

DEPT(DName, DHead)3NF

fd2 S# DName

fd3 DName DHead

DHeadDNameS#

fd S# DHead

Decompose to Eliminate the Transitivity Within S_D

Page 70: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-70

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Another Example of 3NFEMP_DEPT is 2NF with Key SSN, but there are

Two Transitive Dependencies (Undesirable)SSN DNUMBER and DNUMBER DNAME

Means DNAME, Neither Key Nor Subset of Key, is Transitively Dependent on SSN

SSN is the Only Candidate Key of EMP_DEPT!Note: Also Similar Problem with SSN and

DMGRSSN via DNUMBER

Page 71: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-71

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Another Example of 3NFTo Attain 3NF, Decompose into ED1 and ED2Intuitively - we are Separating Out Employees

and Departments from One Another

Page 72: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-72

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Yet Another Example of 3NF

Recall 2NF Solution for Building Lots Problem What is the 3NF Problem? Violate Alternative Defn.

In LOTS1, FD4 AREA PRICEAREA is not a SuperkeyPRICE not a Prime Attribute of LOTS1

Page 73: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-73

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Yet Another Example of 3NF

Decompose to Introduce a Separate Key AREAResult: 3NF for LOTS1A and LOTS1B

Page 74: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-74

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Summary of ProgressionSTUDENT_DEPT

1NF

S# DHead CN GradeDName

fd1

fd2

fd3 S_C S_D2NF

eliminate partial FDs

fd1

S# CN Grade DHeadDName

fd2

fd3

S#

DHead

S#S_D

DName

DEPT

S_C

3NF

eliminate transitive FDs

fd1

S# CN Grade

DName

fd3

fd2

Page 75: Copyright © 2004 Pearson Education, Inc. Functional Dependencies & DB Normalization The main reference of this presentation is the textbook and PPT from.

Slide 10-75

Elmasri and Navathe, Fundamentals of Database Systems, Fourth EditionRevised by IB & SAM, Fasilkom UI, 2005

Summary of 1NF, 2NF, 3NF Concepts

Test Remedy (Normalization)

1NF Relation should have Form new relations for each nonatomic no nonatomic attributes attribute or nested relation. or nested relations.

2NF For relations where primary Decompose and set up a new relation key contains multiple for each partial key with its dependent attributes, no nonkey attribute(s). Make sure to keep a attribute should be relation with the original primary key functionally dependent on and any attributes that are fully a part of the primary key. functionally dependent on it.

3NF Relation should not have a Decompose and set up a relation that nonkey attribute functionally includes the nonkey attribute(s) that determined by another nonkey functionally determine(s) other attribute (or by a set of nonkey nonkey attribute(s). attributes.) That is, there should be no transitive dependency of a nonkey attribute on the primary key.