Docsity

Slides on Normal Forms, Multivalued Dependencies | CMPS 180, Study notes of Database Management Systems (DBMS)

Partial preview of the text

Download Slides on Normal Forms, Multivalued Dependencies | CMPS 180 and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

Winter 2002

Arthur Keller – CS 180

Schedule

•^

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

Normalization

Goal = BCNF = Boyce-Codd Normal Form =all FD’s follow from the fact “key

everything.”

•^

Formally,

R

is in BCNF if for every nontrivial FD

for

R

, say

X

A

, then

X

is a superkey.

◆

“Nontrivial” = right-side attribute not in left side.

Why?1. Guarantees no redundancy due to FD’s.2. Guarantees no

update anomalies

= one occurrence

of a fact is updated, not all.

  1. Guarantees no

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.

Another Example Beers(name, manf, manfAddr)

•^

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–

Decomposition to Reach BCNF

Setting: relation

R

, given FD’s

F

Suppose relation

R

has BCNF violation

X

B

  • We need only look among FD’s of

F

for a

BCNF violation, not those that follow from

F

  • Proof: If

Y

A

is a BCNF violation and

follows from

F

, then the computation of

Y

used at least one FD

X

B

from

F

◆

X

must be a subset of

Y

◆

Thus, if

Y

is not a superkey,

X

cannot be a superkey

either, and

X

B

is also a BCNF violation.

Winter 2002

Arthur Keller – CS 180

4–

Example

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

3NF

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:

AB

C

and

C

B

•^

Example 1:

title city

theatre

and

theatre

city

•^

Example 2:

street city

zip

zip

city

Keys: {

A

,^

B

} and {

A

,^

C

}, but

C

B

has a left side that

is not a superkey.

-^

Suggests decomposition into

BC

and

AC

◆

But you can’t check the FD

AB

→

C

in only these relations.

Winter 2002

Arthur Keller – CS 180

Example

A

street

,^

B

city

,^

C

zip

Join:

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

What 3NF Gives You

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

Multivalued Dependencies

The

multivalued dependency

X

Y

holds

in a relation

R

if whenever we have two

tuples of

R

that agree in all the attributes of

X

, then we can swap their

Y

components

and get two new tuples that are also in

R

X

Y

others

Winter 2002

Arthur Keller – CS 180

4–

MVD Rules

1.Every FD is an MVD.

◆

Because if

X

Y

, then swapping

Y

’s between

tuples that agree on

X

doesn’t create new tuples.

◆

Example, in

Drinkers

:^

name

addr

2.Complementation

: if

X

Y

, then

X

Z

where

Z

is all attributes not in

X

or

Y

◆

Example: since

name

phones

holds in

Drinkers

, so does

name

addr beersLiked

Winter 2002

Arthur Keller – CS 180

Splitting Doesn’t Hold

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

Example

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)