Question

In: Computer Science

INTRO TO DATABASES Consider the boat reservation system: Sailors (sid, sname,rating, age) Boats(bid, bname, color) Reserves...

INTRO TO DATABASES

Consider the boat reservation system:

Sailors (sid, sname,rating, age)

Boats(bid, bname, color)

Reserves (sid, bid, day)

Formulate the following question in relational algebra using two different sequences of relational operators:

A. Find the colors of boats reserved by Lubber.

B. Find the sids of sailors older than 20 who have not reserved a red boat.

Solutions

Expert Solution

Please UPVOTE if it helps.

NOTE :

  • Selection (σ) operator is used to select rows or tuples from relation/table.
  • Projection (π) operator is used to select colums from table.
  • The difference (-) of two relations R and S is the set of tuples that are in R but not in S
  • The natural join (∞) of two relations R and S is a set of pairs of tuples, one from R and one from S, that agree on whatever attributes are common to the schemas of R and S.

A. Find the colors of boats reserved by Lubber.

Solution :  πcolor((σsname= ‘Lubber’ Sailor)∞ Reserves ∞ Boats ))

  1. 1. Find all sailors who's name (sname) is "Lubber". [ (σsname= ‘Lubber’ Sailor) ]
  2. 2. Then find the boats which are reserved by "Lubber". [ (σsname= ‘Lubber’ Sailor)∞ Reserves ∞ Boats ) ]
  3. 3. Now,find colors of boat reserved by "Lubber".

B . Find the sids of sailors older than 20 who have not reserved a red boat.

Solution : πsid (σage>20Sailors) πsid ((σcolor=‘red’ Boats) ∞Reserves)

1. Find all sailors (sids) with age over 20. [ πsid (σage>20Sailors) ]

2. Find all sailors (sids) who have reserved a red boat. [ πsid ((σcolor=‘red’ Boats) ∞Reserves)

3. Now, we can find sids of sailors older than 20 who have not reserved a red boat by taking difference between those people who's age is greater than 20 and those who have reserved the red boat.


Related Solutions

INTRO TO DATABASE Consider the Sailors-Boats-Reserves database described below. Sailors(sid: integer, sname: string, rating: integer, age:...
INTRO TO DATABASE Consider the Sailors-Boats-Reserves database described below. Sailors(sid: integer, sname: string, rating: integer, age: real) Boats(bid: integer, bname: string, color: string) Reserves(sid: integer, bid: integer, day: date) Write each of the following queries in SQL. 1. Find the names and ages of sailors who have reserved at least two boats. 2. For each boat reserved by at least 2 distinct sailors, find the boat id and the average age of sailors who reserved it.
INRO TO DATABASES Consider the following Schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname:...
INRO TO DATABASES Consider the following Schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname: string, color: string) Catalog(sid: integer, pid: integer, cost: real) The Catalog relation lists the prices charged for parts by Suppliers. Write the following queries in SQL using join, nested queries and set operators. 1. Find names of suppliers who supply every red or green part. 2. Find the sids of suppliers who supply every red part or supply every green part. 3. Find sids...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT