Department of Computer Science
CSI481 Database Systems
Lab 6 – Implementation Using MySQL or Oracle
Aim
______________________________________________________________________________
The aim of this lab is to continue to familiarise you with the MySQL/Oracle Database
Management System, enabling you to define relations and constraints and populate a database.
Your Tasks
____________________________________________________________________________
Part 2 - MySQL: Specifying Integrity Constraints
1. The following tables form part of a database held in a relational DBMS:
Hotel (hotelno, hotelname, city)
Room (roomno, hotelno, type, price)
Booking (hotelno, guestno, datefrom. dateto, roomno)
Guest (guestno. guestname, guestaddress)
Where Hotel contains hotel details and hotelno is the primary key; Room contains room details
for each hotel and (roomno, hotelno) forms the primary key; Booking contains details of bookings
and (hotelno, guestno, datefrom) forms the primary key; Guest contains guest details and guestno
is the primary key.
a) Identify the foreign keys in this schema. Explain how the entity and referential integrity
rules apply to these relations.
b) Produce some sample tables (data) on paper for these relations that observe the
relational integrity rules. Suggest some general constraints that would be appropriate for
this schema.
2. Do the following using the relational schema from 1.
a) Create the Hotel table using SQL in MySQL/Oracle. Note the SQL query.
b) Now create the Room, Booking, and Guest tables with the following constraints:
i. Type must be one of ‘Single’, ‘Double’, or ‘Family’.
ii. Price must be between P100 and P1000.
iii. roomno must be between 1 and 100.
iv. datefrom and dateto must be greater than today’s date.
c) Provide some sample data and enter the data using SQL DML commands. Note the
queries.