Formal-Relational Query Languages: Practice Exercises
Formal-Relational Query Languages: Practice Exercises
Formal-Relational Query Languages: Practice Exercises
27
Formal-Relational Query
Languages
Practice Exercises
R = (A, B, C)
S = (D, E, F )
Let relations r(R) and s(S) be given. Give an expression in the tuple relational
calculus that is equivalent to each of the following:
a. ΠA (r)
b. σB = 17 (r)
c. r × s
d. ΠA,F (σC = D (r × s))
27.2 Let R = (A, B, C), and let r1 and r2 both be relations on schema R. Give an
expression in the domain relational calculus that is equivalent to each of the
following:
a. ΠA (r1 )
b. σB = 17 (r1 )
c. r1 ∪ r2
d. r1 ∩ r2
e. r1 − r2
1
2 Chapter 27 Formal-Relational Query Languages
27.5 Let R = (A, B) and S = (A, C), and let r(R) and s(S) be relations. Write
expressions in Datalog for each of the following queries:
a. { < a > | ∃ b (< a, b > ∈ r ∧ b = 17)}
b. { < a, b, c > | < a, b > ∈ r ∧ < a, c > ∈ s}
c. { < a > | ∃ c (< a, c > ∈ s ∧ ∃ b1 , b2 (< a, b1 > ∈ r ∧ < c, b2 > ∈
r ∧ b1 > b2 ))}
27.6 Consider the relational database of Figure 27.13 where the primary keys are
underlined. Give an expression in Datalog for each of the following queries:
a. Find all employees who work (directly or indirectly) under the manager
“Jones.”
Practice Exercises 3
b. Find all cities of residence of all employees who work (directly or indi-
rectly) under the manager “Jones.”
c. Find all pairs of employees who have a (direct or indirect) manager in
common.
d. Find all pairs of employees who have a (direct or indirect) manager in
common and are at the same number of levels of supervision below the
common manager.
27.7 Describe how an arbitrary Datalog rule can be expressed as an extended
relational-algebra view.