Вы находитесь на странице: 1из 24

4NF (Multivalued Dependency), and

5NF (Join Dependency)

Review

Superkey a set of attributes which will


uniquely identify each tuple in a relation
Candidate key a minimal superkey
Primary key a chosen candidate key
Secondary key all the rest of candidate keys
Prime attribute an attribute that is a part of
a candidate key (key column)
Non-prime attribute a non-key column

Narotama University

Review (cont.)
1NF

Eliminate repeating groups.

Make a separate table for each set of related attributes, and give each table a
primary key.

2NF

Eliminate redundant data.

Each attribute must be functionally dependent on the primary key.


If an attribute depends on only part of a multi-valued key, remove it to a
separate table.

3NF

Eliminate columns not dependent on key.

If attributes do not contribute to a description of the key, remove them to a


separate table.
Any transitive dependencies are moved into a smaller table.

BCNF

Every determinant in the table is a candidate key.

If there are non-trivial dependencies between candidate key attributes, separate


them out into distinct tables.

All normal forms are additive, in that if a model is in 3NF, it


is by definition also in 2NF and 1NF.

Narotama University

4NF

Definition

A relation R is in 4NF if and only if, for every one


of its non-trivial multivalued dependencies
XY, X is a superkeythat is, X is either a
candidate key or a superset thereof.

1.
2.

Nontrivial MVD means that:


Y is not a subset of X, and
X and Y are not, together, all the attributes.

Narotama University

Decomposition into 4NF

If XY is a 4NF violation for relation R, we


can decompose R using the same technique
as for BCNF.
1.
2.

XY is one of the decomposed relations.


All but Y X is the other.

Narotama University

Decomposition into 4NF Method


Find a 4NF violation in R, say AB, where A
is not a superkey.
If there is such a 4NF violation, break the
schema for the relation R that has the 4NF
violation into two schemas.

1.
2.

R1, whose schema is As and Bs.


R2, whose schema is the As and all attributes of
R that are not among the As or Bs.

Find the FDs and MVDs that hold in R1 and


R2. Recursively decompose R1 and R2 with
respect to their projected dependencies.
Narotama University

4NF Decomposition Example


Drinkers(name, addr, phones, beersLiked)
FD:
nameaddr
MVDs:
namephones
namebeersLiked
Key is {name, phones, beersLiked}.
All dependencies violate 4NF.

Narotama University

4NF Decomposition Example (cont.)


Decompose using nameaddr:
Drinkers1(name, addr)

1.

Drinkers2(name, phones, beersLiked)

2.

In 4NF; only dependency is nameaddr.


Not in 4NF. MVDs namephones and
namebeersLiked apply. No FDs, so all
three attributes form the key.

Narotama University

4NF Decomposition Example (cont.)

Decompose Drinkers2

Either MVD name ->-> phones or name ->->


beersLiked tells us to decompose to:

Drinkers3(name, phones)
Drinkers4(name, beersLiked)

Narotama University

MVD Example
Drinkers(name, addr, phones, beersLiked)
A drinkers phones are independent of the
beers they like.

namephones and namebeersLiked.

Thus, each of a drinkers phones appears with


each of the beers they like in all combinations.

10

Narotama University

MVD Example (cont.)


Tuples

Implied by namephones

If we have tuples:

name
sue a
sue a
sue a
sue a

11

addr phones beersLiked


p1
b1
p2
b2
p2
b1
p1
b2

Then these tuples must also be in the relation.

Narotama University

Example
Drinkers(name, addr, phones, beersLiked)
with MVD Name phones. If Drinkers has
the two tuples:
name
sue
sue

addr phones
a
p1
b1
a
p2
b2

beersLiked

it must also have the same tuples with phones


components swapped:
name addr phones
sue
a
p2
b1
sue
a
p1
b2

beersLiked

Note: we must check this condition for all pairs


of
name,University
not just one pair.
12 tuples that agree on Narotama

Example (contd)

Violates 4NF because CUSTOMER is not a


superkey
(and CUSTOMER->->LOAN_NO is non-trivial)

13

Narotama University

Solution:

14

Narotama University

HIGHER NORMAL FORMS

1NF

2NF 3NF BCNF 4NF 5NF

functional
dependencies
multivalued
dependencies
join
dependencies
15

Narotama University

ASSUMPTIONS
24-HOUR FLIGHT-TIMETABLE, ALL FLIGHTS EVERY DAY
ALL PLANES TAKE-OFF AND LAND (BUT DO NOT CRASH)
NO AIRPORT IS LANDING-ONLY & NO AIRPORT IS TAKE-OFF-ONLY
TTAB (ORG) = TTAB (DST)
THERE IS AT LEAST ONE TIME DELAY ENTRY FOR EVERY FLIGHT
SIMILARLY IN WEATHER REPORT HISTORY
IF NO TWO FLIGHTS CAN TAKE OFF AT THE SAME TIME IN THE SAME AIRPORT
WES CAN BE POSTED TO FLIGHT AND WEATHER@ORIGIN ELIMINATED

16

Narotama University

AWARD
UNIVERSITY

DISCIPLINE DEGREE

Old Town

Computing

BSc

Old Town

Mathematics

PhD

New City

Computing

PhD

Old Town

Computing

PhD

teaches (UNIVERSITY, DISCIPLINE)


is_read_for (DISCIPLINE, DEGREE)
awards (UNIVERSITY, DEGREE)

teaches (NewCity, Computing) = true


awards (NewCity, PhD) = true
is_read_for (Computing, BSc) = true

FROM
(NewCity teaches Computing) and (Computing is_read_for BSc)
IT DOES NOT FOLLOW
NewCity awards BSc for_reading Computing

17

Narotama University

AWARD

UNIVERS ITY DIS CIPLINE


Old Town
Old Town

Computing

DIS CIPLINE DEGREE UNIVERS ITY DEGREE


Computing

Mathematic s Mathematic s

New City

Computing

Computing

UNIVERS ITY DIS CIPLINE

BS c

Old Town

BS c

PhD

Old Town

PhD

PhD

New City

PhD

DEGREE

Old Town

Computing

BS c

Old Town

Computing

PhD

Old Town

Mathematic s

PhD

New City

Computing

BS c

New City

Computing

PhD

spurious
tuple

UNIVERS ITY DIS CIPLINE

18

DEGREE

Old Town

Computing

BS c

Old Town

Computing

PhD

Old Town

Mathematic s

PhD

New City

Computing

PhD

Narotama University

Join Dependency
JD * (R1, R2, R3, ..., Rm) holds in R iff R = join (R1, R2, R3, ..., Rm ), Ri - a projection of R
for

if

R1

R2

then
)

JD*(
holds for R

19

Narotama University

Fifth Normal Form

preventingillogicalconjunctionoffacts

A relation R is in 5NF iff


for all JD * (R1, R2, R3, ..., Rm) in R,
every Ri is a superkey for R.

if
JD* (

) holds for R

,
does not contain key

then R is not in 5NF

if
JD* (

JD* (

)
)

then R is in 5NF

20

Narotama University

AWARD

UNIVERSITY

DISCIPLINE

DISCIPLINE

DEGREE

UNIVERSITY

DEGREE

Old Town

Computing

Computing

BSc

Old Town

BSc

Old Town

Mathematics

Mathematics

PhD

Old Town

PhD

New City

Computing

Computing

PhD

New City

PhD

21

Narotama University

RANKING
NAME

CODE

TEACHING

RES EARCH

Old Town

P05

21

New City

C01

23

candidate keys - NAME or CODE

join dependencies
JD1 * ((NAME, CODE, TEACHING), (NAME, RESEARCH))
JD2 * ((NAME, CODE, RESEARCH), (NAME, TEACHING))
JD3 * ((NAME, CODE, TEACHING), (CODE, RESEARCH))
JD4 * ((NAME, CODE, RESEARCH), (CODE, TEACHING))
JD5 * ((NAME, CODE), (NAME, TEACHING), (CODE,RESEARCH))
.............................................................................................
all projections in JD1 - to JD5 are superkeys for RANKING 5NF

22

Narotama University

Summary

A multivalued dependency is a statement that


two sets of attributes in a relation have sets of
values that appear in all possible
combinations.
If a relation is in 4NF, then every nontrivial
MVD is really an FD with a superkey on the
left.

23

Narotama University

References

http://www.cs.sjsu.edu/~lee/cs157b/Spring09
Presentation/4NF_and_Multivalued_Dependency
_by_Kristina_Miguel.ppt
http://www.cs.sjsu.edu/faculty/lee/cs157/4N
F%20and%205NF.ppt

24

Narotama University

Вам также может понравиться