DBMS Practice
DBMS Practice
Answer:
sname: A, C, F
Questions – Using Relational Algebra
Expressions
2. Find the names of sailors who have reserved a red boat.
Answer:
Sname: A, C, F
Questions – Using Relational Algebra
Expressions
3. Find the colors of boats reserved by C.
Answer:
Color: green and red
Questions – Using Relational Algebra
Expressions
4. Find the names of sailors who have reserved at least one boat.
We identify the set of all boats that are either red or green (Tempboats, which
contains boats with the bids 102, 103, and 104 on instances B, R, and S). Then
we join with Reserves to identify sids of sailors who have reserved one of these
boats; this gives us sids 22, 31, 64, and 74 over our example instances. Finally,
we join (an intermediate relation containing this set of sids) with Sailors to find
the names of Sailors with these sids. This gives us the names A, C, and F on the
instances B, R, and S.
Questions – Using Relational Algebra
Expressions
5. Find the names of sailors who have reserved a red or a green boat.
Questions – Using Relational Algebra
Expressions
6. Find the names of sailors who have reserved a red and a green boat.
It tries to compute sailors who have reserved a boat that is both red and
green. (Since bid is a key for Boats, a boat can be only one color; this
query will always return an empty answer set.)
Questions – Using Relational Algebra
Expressions
6. Find the names of sailors who have reserved a red and a green boat.
The correct approach is to find sailors who have reserved a red boat,
then sailors who have reserved a green boat, and then take the
intersection of these two sets:
This query illustrates the use of the set-difference operator. Again, we use the
fact that sid is the key for Sailors. We first identify sailors aged over 20 (over
instances B, R, and S, sids 22, 29, 31, 32, 58, 64, 74, 85, and 95) and then
discard those who have reserved a red boat (sids 22, 31, and 64), to obtain
the answer (sids 29, 32, 58, 74, 85, and 95). If we want to compute the
names of such sailors, we must first compute their sids (as shown above),
and then join with Sailors and project the sname values.
Questions – Using Relational Algebra
Expressions
9. Find the names of sailors who have reserved all boats.