Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Formal-Relational Query Languages: Practice Exercises

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CHAPTER

27
Formal-Relational Query
Languages

Solutions for the Practice Exercises of Chapter 27

Practice Exercises

27.1 Let the following relation schemas be given:

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

employee (person name, street, city)


works (person name, company name, salary)
company (company name, city)
manages (person name, manager name)

Figure 27.13 Employee database.

f. ΠA,B (r1 ) ⋈ ΠB,C (r2 )


27.3 Let R = (A, B) and S = (A, C), and let r(R) and s(S) be relations. Write
expressions in relational algebra for each of the following queries:
a. { < a > | ∃ b (< a, b > ∈ r ∧ b = 7)}
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.4 Consider the relational database of Figure 27.13 where the primary keys are
underlined. Give an expression in tuple relational calculus for each of the fol-
lowing queries:
a. Find all employees who work directly for “Jones.”
b. Find all cities of residence of all employees who work directly for
“Jones.”
c. Find the name of the manager of the manager of “Jones.”
d. Find those employees who earn more than all employees living in the
city “Mumbai.”

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.

You might also like