MySQL Practical Exercise
MySQL Practical Exercise
Your Task is to design the “Drinker-Wine Database” for a local bar owner
Question 1
Develop a conceptual diagram using the Chen notation for the “Drinker-Wine” database
given the following information requirements.
“Drinkers drink wines on various days in certain quantities.
A drinker can drink his or her favourite wine on those days
but can also drink any other wine if the favourite one is not
available. Wine quantities are measured in units. A wine
drinker has a unique number, last name, first name, address,
gender, phone number and age. The address of the drinker
consists of the house number and location. Age is calculated
from the date of birth. Wines are identified by a unique wine
number, name, manufacturer, percentage of alcohol and price of
one unit.
Question 2
Translate the “Drinker-Wine” conceptual Schema to sets of relational schemas
Relational Schema:
Drinker(DrinkerNum, Fname, LName, Gender, Phone, DOB, HouseNum, Location)
Wine (WineID, WineName, Winery, %Alcohol, Unit Price)
Drinking Session (SessionNum,DrinkerNum, WineID, Date, QTY)
1
Question 3
Use MySQL scripts to
a) Create the Drinker-Wine database
b) Create the three tables
DRINKER
DrinkerNu FName LNam Gender Phone DOB HouseNum Location
m e
D100 Luke Mauya Male 01234 16/10/71 956 Orange
Grove
D110 John Mauya Male 07756 31/10/98 4285 Rujeko
D121 Mary Dube Female 03357 24/06/88 4302 Mzari
WINE
WineID WineName Winery %Alcohol Unit Price $
W101 Arinto white wine Douro Valley 12.5 5.00
W225 Ice Wine Wine Folly 13.5 25.00
W202 Bianco white wine Bonacquisti 12 6.00
W300 Dutchess red wine Dutchess Wine Trail 12.5 6.00
SESSION
SessionNu DrinkerNum WineID Date QTY
m
S1001 D100 W101 21 February 2022 5
S2345 D121 W101 11 March 2022 8
S4567 D100 W202 13 March 2022 3
S1010 D110 W101 21 February 2022 10
S2025 D121 W225 14 February 2022 2
Question 4
Use MySQL scripts to perform the following queries
1) Insert into the Wine table the following record (W211, Matamba white wine,
Ngunde Wineries, 10, 7)
2) Modify the address of John Mauya to House number 5305 and Location in Mzari
3) Delete all wines whose unit price is less than $4.50
4) Retrieve details of all wines
5) Retrieve details of all drinkers from Orange Grove
6) Give a list of all wineries.
7) List WineIds of all wines that were drunk from 13/02/2022 to 14/02/2022
8) List the names of wines and their unit price that start with the letter “B” or whose unit
cost greater than $9.
9) Sort the session table by date in descending order
10) Create a view from the wine table to view only the wine names and the wineries
where the percentage alcohol is greater than 12%
11) What is the total number of drinkers in the database?
2
12) How many drinkers were there on the 21st of February 2022?
13) Find DrinkerID who consumes most quantities of wine
14) Find DrinkerID who consumes the least quantities of wine
15) Find the total wine consumed
16) Find the average wine consumed by drinker number D100
17) Count the number of drinkers in each location. List the respective locations
18) List the name of drinkers who drank at least once
19) Who drank wine on 21/02/2022?
20) List the names of drinkers and the wine names that they drank
21) Who drank Ice wine?