Introduction to Database Systems - Test 1

TEST [25 Marks]

Time: 60 Minutes


Question One

The library provides books to borrowers. Each book is described by title, edition, and year of publication, and is uniquely identified using the ISBN. Each borrower is described by his or her name and address and is uniquely identified using a borrower number. The library provides one or more copies of each book and each copy is uniquely identified using a copy number, status indicating if the book is available for loan, and the allowable loan period for a given copy. A borrower may loan one or many books, and the date each book is loaned out and is returned is recorded. Loan number uniquely identifies each book loan.

i. Draw a complete ERD to represent the given information. (4 Marks)

ii. From the ERD in i) draw the logical schema (4 Marks)

iii. From the logical schema in (ii) create any two data dictionaries (2 Marks)

iv. From the data dictionaries in (iii) create any two-physical schema (3 Marks)


Question Two

The following tables form part of a database held in a relational DBMS. This database has thousands of records.

Patient (patientNo, patName, patAddr, DoB)
Ward (wardNo, wardName, wardType, noOfBeds)
Contains (patientNo, wardNo, admissionDate)
Drug (drugNo, drugName, costPerUnit)
Prescribed (patientNo, drugNo, unitsPerDay, startDate, finishDate)

Required:
Write SQL statements to solve the following:

i. Add column Gender with data type varchar and size of 8 in the schema Patient. (1 Mark)

ii. Write Statement that will enter the following records in Ward schema. (W12, Watoto, Private and 10) (1 Mark)

iii. Assume the backup on Schema Contains has completed successfully. Write SQL statement to delete Contains schema from the database. Re-implement the schema Contain by enforcing all necessary integrity constraints available in the Contain table (2 Marks)

iv. Re-define Prescribed schema in SQL such that patientNo and drugNo, have the same values as in Patient and Drug relations. Also ensures that when user modify the values in Patient and Drug relations those values should be reflected in Prescribed relation or when the user try to delete the values in either Patient or Drug relation the query should fail. (2 Marks)

v. Write the query to produce a list of patient who have taken drug with number D12 (2 Marks)

vi. List the patient names , ward name and DoB for patients who have been admitted on 08-02-2019 (2 Marks)

vii. Write a query to display the total number of beds available in the Hospital (2 Marks)


END OF EXAMINATION