Docsity

Schema Refinement and Normal Forms - Lecture Slides | CSC 4480, Study notes of Deductive Database Systems

Toggle sidebar
bg1
11/11/2008
1
Schema Refinement & Normal
Forms
CSC 4480
Review
• 1NF = relation
• 3NF: a table is in 3NF if the only
determinants of nonkey columns are
candidate keys
candidate
keys
.
• Often, a table in 3NF is already in 5NF.
• But not always.
• We examine advanced forms: BCNF, 4NF,
5NF.
Redundant Info
• The basic problem is the redundant storage of
information.
• Anomalies:
–
insertion
– update
– deletion
• Basic idea: replace “big” relation with several
smaller ones. The “trick” is to guarantee that the
new relations are equivalent to the original one.
Functional Dependencies
• the FD X→Y hold if, ∀t1, t2 in r:
If t1.X=t2.X then t1.Y=t2.Y
• Closure of a set of F is F+.
•
Armstrong
’
s axioms:
•
Armstrong s
axioms:
–Reflexivity
– Augmentation
– Transitivity
• If we take the original FDs and then apply the
axioms, we obtain the closure. (Theorem 1).
Normal Forms
• 1NF: a relation
•3NF
• BCNF
•4NF
•5NF
Boyce-Codd Normal Form
• For every FD X→A in F, one of following is
true:
–A ∈X (trivial)
X is a superkey
–
X
is
a
superkey
• Each attribute depends on the key, the
whole key, and nothing but the key.
pf3
pf4
pf5

Partial preview of the text

Download Schema Refinement and Normal Forms - Lecture Slides | CSC 4480 and more Study notes Deductive Database Systems in PDF only on Docsity!

Schema Refinement & Normal

Forms

CSC 4480

Review

• 1NF = relation

• 3NF: a table is in 3NF if the only

determinants of nonkey columns are

candidate keyscandidate keys.

• Often, a table in 3NF is already in 5NF.

• But not always.

• We examine advanced forms: BCNF, 4NF,

5NF.

Redundant Info

• The basic problem is the redundant storage of

information.

• Anomalies:

  • insertion
  • update
  • deletion

• Basic idea: replace “big” relation with several

smaller ones. The “trick” is to guarantee that the

new relations are equivalent to the original one.

Functional Dependencies

• the FD X→Y hold if, ∀ t1, t2 in r:

If t1.X=t2.X then t1.Y=t2.Y

• Closure of a set of F is F+.

• • Armstrong’s axioms:Armstrong s axioms:

  • Reflexivity
  • Augmentation
  • Transitivity

• If we take the original FDs and then apply the

axioms, we obtain the closure. (Theorem 1).

Normal Forms

• 1NF: a relation

• 3NF

• BCNF

• 4NF

• 5NF

Boyce-Codd Normal Form

• For every FD X→A in F, one of following is

true:

– A ∈X (trivial)

– X is a superkeyX is a superkey

• Each attribute depends on the key, the

whole key, and nothing but the key.

Third Normal Form

• For every FD X→A in F, one of following is

true:

– A ∈X (trivial)

– X is a superkeyX is a superkey

– A is part of some key for R.

Violations of 3NF

• X is a proper subset of some key K.

Partial dependency.

• ex: registration:

studentid, courseid, student_namet d tid id t d t

• X is not a proper subset of any key.

Transitive dependency.

• ex: tournament winners:

tournament, year, winner, winner_country

3NF vs BCNF

  • For a table to be in 3NF but not BCNF, we must have overlapping candidate keys.
  • Example: branch_customer_relationship(customer_no, branch_no, visiting_frequency, salesperson_no)
  • Rule that each branch will serve a customer through a single salespersonsalesperson. Salesperson works for only one branch. Salesperson works for only one branch
  • Dependency between salesperson_no and branch_no
  • Alternate candidate key: customer_no, salesperson_no
  • Customer_salesperson_relationship(customer_no, salesperson_no, visiting_frequency)
  • Salesperson(salesperson_no, branch)
  • Trade: no longer enforce unique branch-customer-salesperson.
  • Must enforce in program logic.

(Desirable) Properties of

Decompositions

• Lossless-Join: we can recover the original

relation from the decomposed relations.

• Dependency-Preserving: we can enforce

each original FD by examining a singleeach original FD by examining a single

decomposed table.

Decomposition into BCNF

• see algorithm top of p. 623.

• BCNF is more normalized than 3NF, but,

we can’t guarantee that we can generate a’t t th t t

BCNF decomposition that is also

dependency-preserving. But we can for

3NF.

Decomposition into 3NF

• The previous algorithm would generate

3NF. But we already said it is not DP.

• We will need to modify the algorithm.

• This requires the concept of “minimalThi i th t f “ i i l

cover for a set of FDs”.

example

• But what if we tried to use the derived

table as the solution?

• You should be able to see redundancy

problems, even though the table is inp , g

BCNF.

• The problem is a result of a MVD.

• We tried to resolve two many-to-many

relationships with a single table!

• Don’t do that.

Fifth Normal Form

• Stop splitting when:

– any further splitting would violate lossless join

– only splits left are trivial (i.e. same key in both

tables)

• More complex version of example:

additional rule: each dealer can only

operate at a specified set of locations.

• Can we resolve all three relationships with

one entity?

ER diagram – new example Example – individual tables

Dealer Location Smith Sydney Smith Tokyo Philip Sydney Phili P th

Dealer Instrument Smith 90-Day Bill Smith 180-Day Bill Smith 10-Year Bond Philip Perth (^) Philip 180-Day Bill

Location Instrument Sydney 90-Day Bill Sydney 180-Day Bill Tokyo 90-Day Bill Tokyo 10-Year Bond Perth 180-Day Bill

Example – Combined Table

Dealer Location Instrument

Smith Sydney 90-Day Bill

Smith Sydney 180-Day Bill

Smith Tokyo 90-Day Bill

Smith Tokyo 10-Year Bond

Philip Sydney 180-Day Bill

Philip Perth 180-Day Bill

This table is in 4NF, since there are no MVDs. But since we can split the table into three new tables and reconstruct it, it is not yet in 5NF.

Example - continued

• Some three-way relationships are valid.

Problem only when they are derivable

from simpler relationships.

• Suppose authorities decided on case-bypp y

case basis, independent of any rules.

• Any set of two-column tables will either fail

to cover some permitted combinations, or

will generate combinations that are not

permitted.

Example - continued

Dealer Location Instrument

Smith Sydney 90-Day Bill

  • Smith can deal in Sydney
  • Smith can deal in 180-day bills.
  • 180-day bills can be traded in Sydney.

Smith Tokyo 90-Day Bill

Smith Tokyo 180-Day Bill

Philip Sydney 180-Day Bill

  • But, Smith cannot deal in 180- day bills in Sydney.