Query Language _ DPP 03 (of Lec 09)
Query Language _ DPP 03 (of Lec 09)
[MSQ]
and the following relational algebra query. 9. Consider the following Database
BoatID (Age = 35 rating ≥ 5 (sailors) ⋈ Reserves) Tool (TooID, Brand, Price)
BoatID (Rating < 5 (Sailors)⋈Reserves) Jobsite (Location, compensation, Task)
The number of rows returned by the above query ToolBox(ToolBoxID, location)→location is a foreign
is . key to jobsite.
Holds(ToolBoxID, ToolID) →ToolBoxID is a foreign
[MCQ] key to ToolBox. ToolID is a foreign key to Tool.
6. Consider the relation schemas w(P, Q, R), x (S, P, T) And consider the following SQL query.
y(P, Q, R, S, T) and z (R, S, T). A query that uses SELECT DISTINCT T. ToolID
additional operators of relational algebra: FROM Tool T, Holds H, ToolBox B, Jobsite J
((w × x) y) ÷ z.
WHERE T. ToolID = H.ToolId AND H.ToolBoxID =
What will be the result set if we write this query using
only the basic operators of relational algebra? B. ToolBoxID AND B. location = J. location AND J.
(a) Result set of the basic operator’s query will be Task = ‘welding’
greater than the result set of given query. Which of the following would be an equivalent
(b) Result set will only consist of attributes P and Q. relational algebra query?
(c) Some of the operations in query cannot be (a) ToolID (Tool ⋈ Holds ⋈ ToolBox ⋈ task =
performed due to incompatible relation schemas
‘welding’(jobsite))
(d) Query cannot be written by only using basic
operations. (b) ToolID (task = ‘welding’ (Tool ⋈ (Holds ⋈ Tool Box)
⋈ Jobsite)
[MSQ] (c) task = ‘welding’ (ToolID (Tool) ⋈ Holds ⋈ Tool Box
7. Consider the following relational table A ⋈ Jobsite)
A (d) None of the above
P Q R S T
p1 q1 r1 s1 t1 [MSQ]
p2 q2 r2 s2 t2 10. Consider the following two relations A (P, Q) and
Also, consider the decomposition of the relation A into B (R, S). Which of the following statement is/are
relations A1 = (P, Q, R) and A2 = (R, S, T) which of the
TRUE?
following is/are correct based on the above relations.
(a) A1 (A) ⋈ A2 (A) =A (a) The cardinality of (A⋈P = R B) is always larger
(b) A1 (A) ⋈ A2 (A) A than or equal to the size of (A⋈P = R and Q=S B).
(c) PQ →T is true in the table A1 (A) ⋈ A2 (A) (b) The cardinality of (A⋈P = R and Q S B) is always
(d) None of the above larger than or equal to the size of (A⋈P = R and Q = S
B).
[MSQ] (c) These two-expression (P = 5 (A⋈Q=RB)) and (P =
8. Which of the following relational algebra expression
5 (A) ⋈Q=R B) are always equivalent.
is/are always holds correct?
(d) These two expressions (A × B) – (A ⋈ Q = R B) and
(a) (X ⋈ Y) ⋈Z = (Z ⋈ X) ⋈ Y
(b) A (B (X)) = B (A (X) (A⋈Q R B) are always equivalent.
(c) A (B (X)) = B (A (X)
(d) None of the above
3
Answer Key
1. (d) 7. (a, c)
2. (d) 8. (a, b)
3. (c) 9. (a, b)
4. (a) 10. (a, c, d)
5. (1)
6. (c)
4
2. (d) 6. (c)
SELECT DISTINCT P1, P2, P3 …. Pn Given:
w (P, Q, R), x (S, P, T) y(P, Q, R, S, T) and z (R, S, T)
FROM R1, R2, R3….. Rm
(w × x) contains 6 attributes whereas y contains 5
WHERE Q attributes. So, they aren’t union-compatible. Hence
So, from R1, R2, R3…. Rm intersection operation can’t be performed.
Here, there is no join condition, so it will perform NOTE: If number of attributes in Relation A is n and
cartesian product, then select Q and perform number of attributes in relation B is m then number of
projection. attributes “A x B” will be “n + m”.
P1, P2, P3…. Pn (Q (R1× R2 × R3×…… ×Rm))
7. (a, c)
(a) TRUE
3. (c)
(a) When B = , then result of A × B = then it is not A
equivalent to A. So, this equivalence is false. P Q R S T
(b) It is clearly seen that it is false / not equivalence p1 q1 r1 s1 t1
as difference is not commutative. p2 q2 r2 s2 t2
(c) Both expressions are equivalent. In expression
A⋈T(Q, S) (B), first we are performing rename A1(A) A2(A)
P Q R R S T
operation on attribute of relation B and then
p1 q1 r1 r1 s1 t1
performing natural join on common column Q. p2 q2 r2 r2 s2 t2
10. (a, c, d)
(a) True, because (A⋈P=R and Q=S B) is more restrictive
than (A⋈P = R B), it will also filter out the row in
which Q is not equal to S therefore the cardinality
(Number of rows) of (A ⋈P=R B) is always larger
than or equal to the size of (A⋈P = R and Q = S B).