1 Assignment-2
1 Assignment-2
1:
This exercise builds upon the products schema of Exercise 2.3.2. Recall that the
database schema consists of four relations, whose schemas are:
Product(maker, model, type)
PC(model, speed, ram, hd, price)
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)
Some sample data for the relation Product is shown in Fig. 2.20. Sample data for
the other three relations is shown in Fig. 2.21. Manufacturers and model numbers have
been sanitized, but the data is typical of products on sale at the beginning of 2007.
Write expressions of relational algebra to answer the following queries. You may
use the linear notation of Section 2.4.13 if you wish. For the data of Figs, 2.20 and 2.21,
show the result of your query. However, your answer should work for arbitrary data,
not just the data of these figures.
a) What PC models have a speed of at least 3.00?
f) Find those hard-disk sizes that occur in two or more PCs.
h) Find those manufacturers of at least two different computers (PCs or laptops) with
speeds of at least 2.80.
Solutions:
a) The answer is:
(3.00 ())
Result:
1005
1006
1013
f) The answer is:
1 := 1 (PC)
2 := 2 (PC)
3 := 1 1.=2. 1.<>2. 2
R4 1. (3)
Result:
250
80
160
h) The answer is:
R1 := 2.8 (, () , ())
R2 := , (R1 Product)
R3 = 3(2,2) (R2)
R4 = R2 =2 <> 2 R3
Answer(maker) = (R4)
Result:
B
E
PC1 := , (PC)
PC2 := 2(,) (PC1)
Answer(hd) := (PC1 <> PC2)
Note:
Such error happens because many students believe THETA JOIN first do
NATURAL JOIN and then impose condition C. But actually, THETA JOIN
first do Cartesian Product and then impose condition C.