0% found this document useful (0 votes)
110 views2 pages

4 Ex Relalg

This document introduces exercises on relational algebra from a course on databases. It includes a schema with Supplier, Part, and Catalog relations and questions asking to write queries in relational algebra. The questions find suppliers of red parts, suppliers of red or green parts, suppliers matching other criteria, and relationships between supplier costs. It also asks to describe in English the meaning of sample relational algebra queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views2 pages

4 Ex Relalg

This document introduces exercises on relational algebra from a course on databases. It includes a schema with Supplier, Part, and Catalog relations and questions asking to write queries in relational algebra. The questions find suppliers of red parts, suppliers of red or green parts, suppliers matching other criteria, and relationships between supplier costs. It also asks to describe in English the meaning of sample relational algebra queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Introduction to Databases

Fall-Winter 2009/10

Exercises

Michail Kazimianec
Werner Nutt
Damiano Somenzi

4. Relational Algebra
Consider the following schema:
Supplier(sid: integer, sname: string, address: string)
Part(pid: integer, pname: string, colour: string)
Catalog(sid: integer, pid: integer, cost: real)
The relation Supplier stores suppliers and the key of that relation is sid. The relation
Part stores parts, and pid is the key of that relation. Finally, Catalog stores which
supplier supplies which part at which cost. The key is the combination of the two
attributes sid and pid.
1. Write queries in relational algebra
Write the following queries in relational algebra.
1. Find the names of suppliers who supply some red part.
2. Find the IDs of suppliers who supply some red or green part.
3. Find the IDs of suppliers who supply some red part or are based at 21 George
Street.
4. Find the names of suppliers who supply some red part or are based at 21 George
Street.
5. Find the IDs of suppliers who supply some red part and some green part.
(Hint: use intersection of relations or join the same relation several times)
6. Find pairs of IDs such that the supplier with the first ID charges more for some
part than the supplier with the second ID.
(Hint: you may want to create temporary relations to get two copies of Catalog)
7. Find the IDs of suppliers who supply only red parts.
(Hint: A supplier supplies only red parts if it is not the case that the supplier
offers a part that is not red. This question is a challenge!)
8. Find the IDs of suppliers who supply every part.
(Hint: A supplier supplies every part if it is not the case that there is some part
which they do not supply. Use set difference and cartesian product. This question
is a challenge, too!)

2. Queries in relational algebra, what do they mean?


For each of the following relational algebra queries, say in English what they mean.
1. sname (colour=0 red0 (Part) 1 cost<100 (Catalog) 1 Supplier)
2. sname (sid (colour=0 red0 (Part) 1 cost<100 (Catalog)) 1 Supplier)
3. sname (colour=0 red0 (Part) 1 cost<100 (Catalog) 1 Supplier)
sname (colour=0 green0 (Part) 1 cost<100 (Catalog) 1 Supplier)
4. sid (colour=0 red0 (Part) 1 cost<100 (Catalog) 1 Supplier)
sid (colour=0 green0 (Part) 1 cost<100 (Catalog) 1 Supplier)
5. sname (sid,sname (colour=0 red0 (Part) 1 cost<100 (Catalog) 1 Supplier)
sid,sname (colour=0 green0 (Part) 1 cost<100 (Catalog) 1 Supplier))

References
Most of these exercises are taken from the book Database Management Systems by
Ramakrishnan/Gehrke, Chapter 4.

You might also like