Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Workshop Week 5 – MySQL Practical Exercise

Exercise 1

1. Create the database sbr and the following tables sailors, boats, and
reserves which are reproduced as follows:

sailors(sid:VARCHAR (2) PK, sname:VARCHAR(7), rating:


SMALLINT, age: DOUBLE
boats(bid: VARCHAR (3) PK, bname: VARCHAR (10), colour:
VARCHAR(6)
reserves(sid: VARCHAR(2) FK, bid: VARCHAR(3) FK, day: DATE)

sid sname rating age sid bid Day bid bname colour

22 Dustin 7 45.0 22 101 10/10/98 101 Interlake blue


29 Brutus 1 33.0 22 102 10/10/98 102 Interlake red
31 Lubber 8 55.5 22 103 10/8/98 103 Clipper green
32 Andy 8 25.5 22 104 10/7/98 104 Marine red
58 Rusty 10 35.0 31 102 11/10/98
64 Horatio 7 35.0 31 103 11/6/98 Boats
71 Zorba 10 16.0 31 104 11/12/98
74 Horatio 9 35.0 64 101 9/5/98
85 Art 3 25.5 64 102 9/8/98
95 Bob 3 63.5 74 103 9/8/98

Sailors Reserves

2. Using MySQL Workbench, construct the three tables for the sailors,
boats, and reserves accordingly. Enter the test data for the three tables
as shown above, and formulate MySQL queries to answer the following
questions.

Note: The above tables are related as 1:M relationship, “A sailor can
reserve many botas and a boat can be reserved by many sailors” can be
implemented via “Reserves” bridge entity.

3. Discuss- the need and requirements of a bridge entity and why it is not
advisable to implement many- to- many relationships in database directly.
 A bridge entity has been used to indicate a many-to-many connection
that can't be described using basic specificity of a single piece of
evidence or scale object. To providing multi-valued measurement
attributes, a bridge entity combines the truth and measurement objects.
This particular utilization is permitted by the given DWM's bridge
structures. The primary key of a link is important in this scenario, and
a bridge object can handle even one-to-many relationships across

1
aspect objects. Relational objects were used to reference to bridge
entities in the past.

4. Find all sailors with a rating above 7.

SELECT * FROM sailors where rating > 7;

5. Find the sailor ID and boat ID of those boats reserved on 10/10/98.

SELECT sailors.sid, boats.bid


from sailors
JOIN reserves on sailors.sid = reserves.sid
JOIN boats on boats.bid = reserves.bid
WHERE reserves.reserve_day = '1998-10-10

2
6. Find the sailor ID and boat ID of those boats reserved from 10/10/98 to
1/12/98 inclusive.

SELECT sailors.sid, boats.bid


from sailors
JOIN reserves on sailors.sid = reserves.sid
JOIN boats on boats.bid = reserves.bid
WHERE reserves.reserve_day between '1998-10-10' AND '1998-11-12'

You might also like