CPSC 2221 - Database System
Lab 6 – RA and Datalog
Individual
Lab
Total
Marks: 68
Question 1. Consider
the following relational schema, write expressions of relational algebra and
Datalog to answer the following queries
Product ( pid, name, price, category, maker-cid)
Purchase (buyer-sin, seller-sin, store,
pid)
Company (cid, name, stock price,
country)
Person(sin, name, phone number,
city)
1. Find the name of all products:
RA |
|
Datalog |
|
2. Find the
countries of all the companies
Datalog |
|
3. Find all purchases with the same buyer and seller:
RA |
|
Datalog |
|
4. Find all products over $99.99:
RA |
|
Datalog |
|
5. Find all English companies (country=England) with stock prices
less than $100
Datalog |
|
6. Find the names of all products over $99.99:
RA |
|
Datalog |
|
7. Find store names where Fred bought something:
RA |
|
Datalog |
|
8. Find names of people who bought from “Gizmo Store”
Datalog |
|
9. Find SINs of people who bought products in the “computers” category.
Datalog |
|
10. Find the sin of people who
bought Canadian products
Datalog |
|
11. Find pairs of products (pid’s) of the same category but with
different makers. Avoid duplicate pairs, e.g., (p1, p2) and (p2, p1) shouldn’t
both appear in the answer.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
27 | 28 | 29 | 30 | 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |