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

Lab 1

The document describes a database schema with three tables: Sailors, Boats, and Reserves. The Sailors table contains information about sailors, the Boats table contains information about boats, and the Reserves table links sailors and boats to show boat reservations. Ten relational algebra queries are provided to retrieve information from the tables, such as the names of sailors who have reserved specific boats.

Uploaded by

Trương Nhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

Lab 1

The document describes a database schema with three tables: Sailors, Boats, and Reserves. The Sailors table contains information about sailors, the Boats table contains information about boats, and the Reserves table links sailors and boats to show boat reservations. Ten relational algebra queries are provided to retrieve information from the tables, such as the names of sailors who have reserved specific boats.

Uploaded by

Trương Nhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Giving a database schema:

- Sailors(sid: integer, sname: string, rating: integer, age:real)


- Boats(bid:integer , bname: string, color: string)
- Reserves(sid: integer, bid: integer , day: date )

Boats

Sailors Reserves

Using relational algebra expression to answer below queries

1. Find the names of sailors who have reserved boat 103


2. Find the names of sailors who have reserved a red boat
3. Find the colors of boats reserved by Lubber
. π ¿(( σ ' '
sname¿ lubbe r sailor ) Sailor ⋈ reserves ⋈ Boats)¿

4. Find the names of sailors who have reserved at least one boat.

π sname ¿)

5. Find the names of sailors who have reserved a red or a green boat

ρ¿
π sname ¿

6. Find the names of sailors who have reserved a red and a green boat

ρ ¿((σ '¿¿ ℜd ' ¿ boats ¿ ⋈ reserves ¿ ¿


ρ ¿((σ '¿¿ ' green' ¿ boats ¿ ⋈ reserves ¿ ¿
π sname ¿

7. Find the sids of sailors with age over 20 who have not reserved a red boat
' '
π sid ( σ age >20 sailors )−π sid ((σ ¿ ¿ ℜd ¿ boats)⋈ reserves ⋈ sailors)

8. Find the names of sailors who have reserved all boats

ρ(tempsids ,( π sid ,bid Reserves)/(π bidBoats ))


π sname (Tempsids ⋈ Sailors ¿

9. Find the names of sailors who have reserved all boats called Interlake

ρ ¿Reserves)/( π bid ¿ )))


π sname ¿)

10. Find the names of sailors who have reserved at least two boats

ρ ¿)

ρ ( Reserv ationpairs (1 → sid 1,2 → sname , 3→ bid 1,4 → sid 2,5 → sname , 6 → bid 2 ) , Reservations× Reservations
π sname 1 σ (sid 1=sid 2)∧(bid 1 ≠bid 2) Reservationpairs ¿

You might also like