COMS 340

advertisement
COMS 340
Fall 2001
Hart
Solutions to Homework Exercises
2.
Given an example (not from the book) of each type (deletion, insertion,
modification) of anomaly for the schema and table shown in Fig. 5.1.
There are lots of way to answer this question. Here’s but one example:
Insertion anomaly: Suppose that we try to insert the tuple (146, 12/26/95, Lady
and the Tramp, animated drama, 93, R) into the Videotape relation. This would
create an inconsistency with the other two tuples already in the relation with
“Lady and the Tramp” as the value for the title attribute. These other two tuples
have a value of PG for the rating attribute.
Modification anomaly: Consider what happens if we decide to change the rating
“Lady and the Tramp” from PG to PG-13. Since there are two entries for “Lady
and the Tramp” we must make the change in two places, not just one.
Deletion anomaly: Unfortunately, on this one, we have to use the same example
as the book. However, we can come at it from a slightly different more general
direction. Notice that if we have a single title matched with a single Video_ID
listed in the Videotape relation (as with Annie Hall), then deleting that videotape
also deletes all information about the movie.
8. These were already done in class but here they are again:
FD9:
1. {purchaseOrderID, supplierID, street}
{supplierID, street} reflexivity
FD10:
1. zipcode
{city, state} FD4
{zipcode, dateOrdered}
{city, state, dateOrdered} 1, augmentation
FD11:
1. purchaseOrderID
2. purchaseOrderID
3. supplierID
4. purchaseOrderID
{supplierID, dateOrdered} FD1
supplierID 1, Decomposition
supplierName FD2
supplierName 2, 3 Transitivity
FD12:
1. zipcode
2. zipcode
{city, state} FD4
state 1, decomposition
FD13:
1. supplierID
2. supplierID
3. supplierID
supplierName FD2
{street, zipcode} FD3
{supplierName, street, zipcode} 1,2 Union
FD 14:
1. movieID
title FD6
2. {title, dateOrdered}
3. {movieID, dateOrdered}
quantity FD7
quantity 1,2 Pseudo-transitivity
Suppose R: (A, B, C, D, E, F, G, H) is a relation.
10. With no functional dependencies defined, what is the key of R?
With no functional dependencies defined, it is not possible to define the key of R.
Alternatively, one might specify that the key of R consists of all of A, B, C, D, E, F,
G, and H.
11. Suppose {A, B} is the key of R, and A
B
{E, F, H}.
{C,D} and
b. Which dependencies represent 2NF violations?
Both specified dependencies represent 2NF violations since both {C,D} and
{E, F, H} functionally depend on a part but not all of the primary key.
c. To eliminate these 2NF violations we decompose into three relations as follows:
i. {A, B, G}
ii. {A, C, D}
iii {B, E, F, H}
Note that while A and B are together the primary key of (i), they are individually
foreign keys referencing the primary keys of (ii) and (iii).
d. There are no violations of 3rd normal form.
e. There are none to eliminate.
12. Suppose A
E
{B, C, D, F, G}, B
{G, H}.
{C, D}, and
a. Which sets of attributes are the keys of R?
With this one, I was more than happy if you were able to find a single key for R.
Remember that a key is a minimal superkey and that a superkey is a set of attributes
that functionally determine all attributes. It’s easy to find a key for R if we are given
the following derived inference rule:
If X
Y and W
Z then XW
YZ
The validity of this rule can be easily shown as follows:
1. X
2. W
3. XW
4. YW
5. XW
Y given
Z given
YW 1, Augmentation
YZ 2, Augmentation
YZ 3, 4 Transitivity
Given this rule, it’s easy to see that {A, E} constitutes a superkey for R since we have
immediately that {A, E}
{B, C, D, F, G, H}. It’s also easy to see that {A, E}
is a key for R since neither A nor E alone constitute a superkey. While it might be
tempting to say that {A, B, E} is a key for R, the best that can be said is that it is a
superkey for R but it is not a key since it is not minimal.
b. Identify and eliminate any 2 NF violations
Using {A, E} as the primary key for R we see that the first and third of the listed
functional dependencies are violations of 2 NF since both {B, C, D, F, G} and {G,
H} are dependent on a part but not all of the primary key. To eliminate these we
decompose as follows:
i. (A, B, C, D, F, G)
ii. (E, G, H)
iii. (A, E)
c. Identify and eliminate any 3 NF violations
Notice that we have a transitive dependency present in (i), viz.
A
B
B
{C, D}
and none of B, C or D are key attributes.
To eliminate this we decompose (i) as follows:
i’. (A, B, F, G)
i’’. (B, C, D)
Download