0% found this document useful (0 votes)
78 views3 pages

RA Datalog Tutorial Sol

The document provides exercises on relational algebra and Datalog queries over a sailors-boats-reserves database. It describes the database schema and provides 12 queries to formulate in both relational algebra and Datalog. For each query, it lists the relational algebra and Datalog formulations in abbreviated form.

Uploaded by

study material
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)
78 views3 pages

RA Datalog Tutorial Sol

The document provides exercises on relational algebra and Datalog queries over a sailors-boats-reserves database. It describes the database schema and provides 12 queries to formulate in both relational algebra and Datalog. For each query, it lists the relational algebra and Datalog formulations in abbreviated form.

Uploaded by

study material
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/ 3

Exercises on Relational Algebra and Datalog

Part I
Go over these exercises before you attend your tutorial. For each exercise, try it first and then
look at the answer. Discuss with the TA’s any problems you may have.

Question

Consider the Sailors-Boats-Reserves DB described in the text.


s (sid, sname, rating, age)
b (bid, bname, color)
r (sid, bid, date)
Write each of the following queries in RA and in Datalog.

1. Find the colors of boats reserved by Albert.


2. Find all sailor id’s of sailors who have a rating of at least 8 or reserved boat 103.
3. Find the names of sailors who have not reserved a red boat.
4. Find the sailor id’s of sailors with age over 20 who have not reserved a red boat.
5. Find the names of sailors who have reserved at least two boats.
6. Find the names of sailors who have reserved all boats.
7. Find the names of sailors who have reserved all boats called BigBoat.
8. Find the sailor id’s of sailors whose rating is better than some sailor called Bob.
9. Find the sailor id’s of sailors whose rating is better than every sailor called Bob.
10. Find the sailor id’s of sailors with the highest rating.
11. Find the name and age of the oldest sailor.
12. Find the names of sailors who have reserved every boat reserved by those with a lower
rating.

Answers
1. [( ( )) ]

( ) ( ) ( ) ( )

2. ( ( )) [ ( )]

( ) ( )
( ) ( )

3. ([ ( ) ( ( ) )] )
( ) ( ) ( )

( ) ( ) ( )

4. ( ( )) – ( ( ) )

( ) ( ) ( )

( ) ( ) ( )

5. [( ( ( )) ].

( ) ( ) ( ) ( )

6. ([ ( ) ( )] )

( ) ( ) ( )
( ) ( ) ( ) ( )
( ) ( )

7. ([ ( ) ( ( ))] )

( ) ( ) ( )
( ) ( ) ( ) ( )
( ) ( )

8. ( [ ( ) ( )])

( ) ( ) ( )

9. ( )– ( [ ( ) ( )])

( ) ( ) ( )
( ) ( ) ( )
10. ( )– ( [ ( ) ])

( ) ( ) ( )
( ) ( ) ( )

11. ([ ( )– ( ( ( ) ))] )

( ) ( ) ( )
( ) ( ) ( )

[ ( ( ))]

( )

( )

[ ( ) ( )] ( )]

Note: Above, we used abbreviations for brevity: e.g., sALS abbreciates


sailorsAndLesserSailors.

( ) ( ) ( )

( ) ( ) ( ) ( ) ( )

( ) ( )

You might also like