Which to use for this relational calculus query, the "for all" quantifier" or the "there exists" quantifier?

60 Views Asked by At

Let's say the following relations are given:

  • Sailors(sid, sname, rating, age)
  • Boats(bid, bname, color)
  • Reserves(sid, bid, day)

What will be the tuple relation calculus query to Find the sailor name, boat id, and reservation date for each reservation?

According to me, the query should be the following: $$\{P|\forall R\in\text{Reserves}(\exists S\in\text{Sailors}(R.\text{sid}=S.\text{sid}\land P.\text{sname}=S.\text{sname}\land P.\text{bid}=R.\text{bid}\land P.\text{day}=R.\text{day}))\}$$

However, according to my book, the query should use the "there exists" quantifier on Reserves: $$\{P|\exists R\in\text{Reserves}\exists S\in\text{Sailors}(R.\text{sid}=S.\text{sid}\land P.\text{sname}=S.\text{sname}\land P.\text{bid}=R.\text{bid}\land P.\text{day}=R.\text{day})\}$$

Which one is correct and why?

1

There are 1 best solutions below

0
On BEST ANSWER

With your query, you're requiring each $P$ that you find to have the same .day as every $R$ in Reserves. In other words, if there are two reservations with different days, it won't find anything. I suggest trying this out by hand on a mini data set with two different reservations on two different days to see the issue.