Exercise 5: Queries as Datalog Programs

Q1. Consider the following datalog program

T(x,z) :- R(x,y), S(y,z), y > 2
T(x,z) :- R(x,y), S(y,z), z > 6

a) Use the assignment table method to construct the result of relation T.

b) Write the relational algebra query corresponding the data log program.

Q2. Adapted from Exercise 2.4.1 from the textbook. The products database consists of 4 relational instances with the following schemas

Product(maker, model, type) 
Laptop(model, speed, ram, hd, screen, price)
PC(model, speed, ram, hd, price) 
Printer(model, color, type, price)

Write datalog programs for the following queries.

a. What PC models have a speed of at least 3.00?

b. Which manufacturers make laptops with a hard disk of at least 100GB?

c. Find the model number and price of all products (of any type) made by manufacturer B.

d. Find the model numbers of all color laser printers.

e. Find those manufacturers that sell Laptops, but not PC’s.

f. Find those hard disk sizes that occur in two or more PC’s.