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

Lab 1

The document provides a schema for sailors, boats, and reservation tables and examples of relational algebra queries on the tables. It defines the tables with attributes and provides sample data. It then lists 10 relational algebra queries to retrieve information from the tables.
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)
28 views2 pages

Lab 1

The document provides a schema for sailors, boats, and reservation tables and examples of relational algebra queries on the tables. It defines the tables with attributes and provides sample data. It then lists 10 relational algebra queries to retrieve information from the tables.
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 )

Sid Sname Rating Age Sid Bid Day Bid Bname Color
22 Dustin 7 45.0 22 101 10/10/08 101 Interlake Blue
29 Brutus 1 33.0 22 102 10/10/08 102 Interlake Red
31 Lubber 8 55.5 22 103 10/08/08 103 Clipper Green
32 Andy 8 25.5 22 104 10/07/08 104 Marine Red
58 Rusty 10 35.0 31 102 11/10/08
Boats
64 Horatio 7 35.0 31 103 11/06/08
71 Zorba 10 16.0 31 104 11/12/08
74 Horatio 9 35.0 64 101 9/05/08
85 Art 3 25.5 64 102 9/08/08
95 Bob 3 63.5 74 103 9/08/08
Sailors Reserves

Using relational algebra expression to answer below queries

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

π Sname (σ Bid=103 ( Reserves ) ⋈ Sailors)

2. Find the names of sailors who have reserved a red boat

π Sname (σ ¿red ( Reserves ⋈ Boats ) ⋈ Sailors)

3. Find the colors of boats reserved by Lubber.


π ¿(σ Sname =Lubber
( Reserves ⋈ Sailors ) ⋈ Boats )¿

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

π Sname (σ ( Reserves ) ⋈ Sailors)

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

π Sname (σ ¿red ∪¿ green ( Reserves ⋈ Boats ) ⋈ Sailors)

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

π Sname (σ ¿red ( Reserves ⋈ Boats ) ⋈ σ ¿green ( Reserves ⋈ Boats ) ⋈ Sailors)

7. Find the sids of sailors with age over 20 who have not reserved a red boat
π Sid (σ age> 20 ( Sailors ) {σ ¿ ¿ ¿ red ( Reserves ⋈ Boats ))

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


π Sname (σ bid= All(Boats) ( Reservers ) ⋈ Sailors )
9. Find the names of sailors who have reserved all boats called Interlake
π Sn ame ( σ Bname=Interlake ( Boats ) ¿ σ bid= All(Boats) ( Reservers ) ⋈ Sailors )

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

11.
π Sname (σ sid= ANY (reserves ) ( Reserves ) ⋈ Sailors )¿ π Sname (σ sid= ANY (reserves ) ( Reserves ) σ bid= ANY (reserves ) ( Reserves ) ) ⋈ Sailors ¿

You might also like