











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












Winter 2002
Arthur Keller – CS 180
Today: Jan. 15 (T)^ ◆
Normal Forms, Multivalued Dependencies. ◆
Read Sections 3.6-3.7. Assignment 1 due.
-^
Jan. 17 (TH)^ ◆
Relational Algebra. ◆
Read Chapter 5. Project Part 1 due.
-^
Jan. 22 (T)^ ◆
SQL Queries. ◆
Read Sections 6.1-6.2. Assignment 2 due.
-^
Jan. 24 (TH)^ ◆
Subqueries, Grouping and Aggregation. ◆
Read Sections 6.3-6.4. Project Part 2 due.
Winter 2002
Arthur Keller – CS 180
Goal = BCNF = Boyce-Codd Normal Form =all FD’s follow from the fact “key
everything.”
Formally,
is in BCNF if for every nontrivial FD
for
, say
, then
is a superkey.
◆
“Nontrivial” = right-side attribute not in left side.
update anomalies
= one occurrence
of a fact is updated, not all.
deletion anomalies
= valid fact is
lost when tuple is deleted.
Winter 2002
Arthur Keller – CS 180
Each of the given FD’s is a BCNF violation:•^
Key = {
name
beersLiked
◆
Each of the given FD’s has a left side that is a propersubset of the key.
FD’s =
name
manf
manf
manfAddr
Only key is
name
◆
Manf
→
manfAddr
violates BCNF with a left side
unrelated to any key.
Winter 2002
Arthur Keller – CS 180
4–
◆
must be a subset of
◆
Thus, if
is not a superkey,
cannot be a superkey
either, and
is also a BCNF violation.
Winter 2002
Arthur Keller – CS 180
4–
R
=
Drinkers(name, addr, beersLiked, manf,favoriteBeer) F
=
name
→
addr
name
→
favoriteBeer
beersLiked
→
manf
Pick BCNF violation
name
→
addr
.
-^
Close the left side:
name
=
name addr favoriteBeer
.
-^
Decomposed relations:^ Drinkers1(name,
addr,
favoriteBeer)
Drinkers2(name,
beersLiked,
manf)
-^
Projected FD’s (skipping a lot of work that leads nowhereinteresting):^ ◆
For
Drinkers
:^ name
→
addr
and
name
→
favoriteBeer
.
◆^
For
Drinkers
:^ beersLiked
→
manf
.
Winter 2002
Arthur Keller – CS 180
(Repeating)•^
Decomposed relations:^ Drinkers1(name,
addr,
favoriteBeer)
Drinkers2(name,
beersLiked,
manf)
-^
Projected FD’s:^ ◆
For
Drinkers
:^ name
→
addr
and
name
→
favoriteBeer
.
◆^
For
Drinkers
:^ beersLiked
→
manf
.
BCNF violations?^ ◆
For
Drinkers
,^ name
is key and all left sides of
FD’s are superkeys. ◆
For
Drinkers
, {
name
,^ beersLiked
} is the key,
and
beersLiked
→
manf
violates BCNF.
Winter 2002
Arthur Keller – CS 180
One FD structure causes problems:•^
If you decompose, you can’t check all the FD’s onlyin the decomposed relations.
-^
If you don’t decompose, you violate BCNF. Abstractly:
and
Example 1:
title city
theatre
and
theatre
city
Example 2:
street city
zip
zip
city
Keys: {
} and {
}, but
has a left side that
is not a superkey.
-^
Suggests decomposition into
and
◆
But you can’t check the FD
AB
→
C
in only these relations.
Winter 2002
Arthur Keller – CS 180
street
zip
545 Tech Sq.
0 2 1 3 8
545 Tech Sq.
0 2 1 3 9
c i t y
zip
Cambridge
0 2 1 3 8
Cambridge
0 2 1 3 9
c i t y
street
zip
Cambridge
545 Tech Sq.
0 2 1 3 8
Cambridge
545 Tech Sq.
0 2 1 3 9
zip
→
city
street
city
→
zip
Winter 2002
Arthur Keller – CS 180
There are two important properties of a decomposition:1.
We should be able to recover from the decomposedrelations the data of the original. ◆^
Recovery involves projection and join, which we shall defer untilwe’ve discussed relational algebra.
We should be able to check that the FD’s for the originalrelation are satisfied by checking the projections of thoseFD’s in the decomposed relations.
-^
Without proof, we assert that it is always possible todecompose into BCNF and satisfy (1).
-^
Also without proof, we can decompose into 3NF andsatisfy both (1) and (2).
-^
But it is not possible to decompose into BNCF and getboth (1) and (2). ◆^
Street-city-zip is an example of this point.
Winter 2002
Arthur Keller – CS 180
others
Winter 2002
Arthur Keller – CS 180
4–
◆
Because if
, then swapping
’s between
tuples that agree on
doesn’t create new tuples.
◆
Example, in
Drinkers
name
addr
◆
Example: since
name
phones
holds in
Drinkers
, so does
name
addr beersLiked
Winter 2002
Arthur Keller – CS 180
Sometimes you need to have several attributes on the right of an
MVD. For example: Drinkers(name,
areaCode, phones,
beersLiked,
beerManf)^ name
areaCode
phones
beersLiked
beerManf
Sue
831
555-
Bud
A.B.
Sue
831
555-
Wicked Ale
Pete’s
Sue
408
555-
Bud
A.B.
Sue
408
555-
Wicked Ale
Pete’s
-^
name
→→
areaCode phones
holds, but neither
name
→→
areaCode
nor
name
→→
phones
do.
Winter 2002
Arthur Keller – CS 180
Drinkers(name,
addr,
phones,
beersLiked)
-^
FD:
name
→
addr
-^
Nontrivial MVD’s:
name
→→
phones
and
name
→→
beersLiked
.
-^
Only key: {
name, phones,
beersLiked
}
-^
All three dependencies above violate 4NF.
-^
Successive decomposition yields 4NF relations:^ D1(name,
addr)
D2(name,
phones)
D3(name,
beersLiked)