1718 Sem 2
1718 Sem 2
Programme Board
Instructions:
(a) This paper has a total of SIX pages
HIGHER DIPLOMA IN
including the covering page.
(b) This paper contains FOUR questions. TELECOMMUNICATIONS AND NETWORKING
(c) Answer ALL questions. (IT114103)
MOBILE APPLICATIONS DEVELOPMENT
Note: The result of this assessment will not be
(IT114112)
counted if you do not meet the
minimum attendance requirement (if
any) governed by the general academic
regulations of your programme/course
unless approval of the campus principal
has been granted.
MODULE TITLE:
DATABASE PRINCIPLES
MODULE CODE: ITP4903
SEMESTER TWO
MAIN EXAMINATION
9 MAY 2018
1:30 PM TO 3:30 PM (2 hours)
© Vocational Training Council
Q1. The followings are the relations of a library system. The database schema with sample data
can be found in the Appendix on page 5.
STUDENT (StudentID, StudentName, Address, Phone)
BOOK (BookID, BookName, Category, Price)
BORROW (BookID, StudentID, BorrowDate, ReturnDate)
Note: The underlined attributes are the primary key attributes.
Assume that the tables STUDENT and BOOK had been created with primary key in the
database and given the following details of the BORROW table:
BORROW
Primary Key
Column Name Type: Length Null? Foreign Key information
information
Foreign key referring to BOOK
BookID Character: 4 No Primary key
table
Foreign key referring to
StudentID Character: 3 No Primary key
STUDENT table
BorrowDate Date No Primary key
Write a SINGLE SQL statement for each of the following questions (except for part (g)):
(a) Create the table BORROW using the above details with Borrow_pk and [7 marks]
Borrow_BookID_fk and Borrow_StudentID_fk as the constraint names
for the primary key and the two foreign keys, respectively.
(b) Change the BOOK table by adding a constraint so that the column [3 marks]
Category must either be Fiction or Technology, use the constraint name
Book_Category_cc.
(c) The BookName column in the BOOK table is not long enough, change its [2 marks]
length to 40 characters.
(d) Set the default value on the column BorrowDate to system date. [2 marks]
(e) Create an index named BookName_idx on the column BookName of the [2 marks]
BOOK table.
(g) Remove the tables STUDENT, BOOK and BORROW in correct order with [2 marks]
multiple SQL statements.
Q2. The relations of a library system and the database schema with sample data found in the
Appendix on page 5 are shown as follows:
STUDENT (StudentID, StudentName, Address, Phone)
BOOK (BookID, BookName, Category, Price)
BORROW (BookID, StudentID, BorrowDate, ReturnDate)
Note: The underlined attributes are the primary key attributes.
(a) Add a new record to the BORROW relation for book B304 borrowed by [2 marks]
student S02 on 15 May 2018, with an unknown return date.
(c) Delete the borrowing record for the book B304 borrowed by student S03 [3 marks]
on 30 Apr 2018.
(e) Display the information of students who have borrowed book(s) but not [4 marks]
yet returned (i.e., the return date is still unknown). Display the student
names and the borrow dates.
(f) Display the information of students who have borrowed books from the [6 marks]
library for more than one time. Display their student IDs and the count.
Sort the output in descending order of the count.
(g) Display the information of students and books they borrowed. Display [6 marks]
their student IDs, student names, book IDs and book names. Sort the
output in ascending order of student names and then descending order of
book names.
(h) Display the information of students who borrowed the same book from [4 marks]
the library. Display their student IDs. For the sample data in page 5, it
should output the following. The FIRST_ID and SECOND_ID are the
student IDs of two different students. And the smaller student ID should
display first.
FIRST_ID SECOND_ID
-------- ---------
S01 S02
Q3 Consider the following table with sample data of a Pet Clinic that keeps owners’ booking
record of treatments for their pets:
BOOKING
PetNo PetName PetType PetAge OwnerNo OwnerName Date TreatNo TreatName
339 DotDot DOG 12 331 Daniel Chan21-JAN-17 01 VACCINATION / A
21-JAN-17 09 TREAT WOUND
08-MAY-17 04 BLOOD TEST
246 SPOT DOG 2 165 Susan Wong 21-JAN-17 02 VACCINATION / B
21-JAN-17 04 BLOOD TEST
109 Milk CAT 4 223 John Chan 30-AUG-17 01 VACCINATION / A
722 KatKat BIRD 2 261 Calvin Lee 05-APR-17 20 ANNUAL CHECK UP
11-NOV-17 12 EYE WASH
Where
PetNo = unique pet identification number; OwnerName = pet owner’s name;
PetName = pet name; Date = booking date;
PetType = pet type; TreatNo = medical treatment number;
PetAge = pet age; TreatName = medical treatment name;
OwnerNo = unique pet owner identification number.
Assumptions:
1. Each pet has a name and a unique pet number.
2. Each pet owner has a name and a unique owner number.
3. Each pet has one owner and an owner can have one or many pets.
4. Each pet can have one or more booking but a booking can have only one pet.
5. A booking can have only one treatment but a treatment can be exercised on zero or
many bookings. Multiple bookings are required for multiple treatments of a pet on the
same day.
(a) Explain, with example, how modification anomaly may happen in the [2 marks]
BOOKING relation.
(b) Name and describe the TWO other types of database anomalies that may [4 marks]
happen in the BOOKING relation.
(c) (i) Explain the term “Normalization” and ANY TWO conditions required
by 1NF [3 marks]
(ii) Write down the unnormalized form (UNF) for the BOOKING relation. [1 mark]
(ii) Normalize the BOOKING relation to the third normal form (3NF). Show [12 marks]
ALL your steps from 1NF to 3NF by listing all the relations in 1NF,
2NF and 3NF. Underline the primary key attribute(s) for each relation
in your answer.
(d) Draw an entity relationship diagram to represent the normalized relations in [8 marks]
3NF based on the given assumptions. Make sure that all entities must be
labelled and relationships must be drawn with the correct symbols.
Assume a doctor can have many patients and a patient can only associated with one doctor.
The underlined attributes are primary keys of the PATIENT and DOCTOR relations.
Sample data of the PATIENT relation:
PatientID Name Gender HKID Phone DoctorID
P011254 Leung Cheuk Yin Female G918237(7) 90215455 D002
P000151 Mak Yu Hin Male Z215487(2) 32145670 D301
P271568 Zhang Xinzhi Male Y242424(5) 65840267 D002
P008953 Au Ka Lung Male C668668(A) 85462452 D041
(a) Define the following database terms, and give TWO examples for EACH
term with suitable attribute(s) from the PATIENT relation (a total of four
examples):
(i) Superkey; [3 marks]
(ii) Alternate Key. [3 marks]
(c) (i) Describe how the Entity Integrity rule can be enforced between the [2 marks]
DOCTOR relation.
(ii) Explain why the following SQL statement when executed may result in [2 marks]
run time error.
DROP TABLE DOCTOR;
APPENDIX
This is a library system for recording student and book information. The database also records
borrow / loan information. A student can borrow many books and a book can be borrowed by
many students. Furthermore, one can borrow a book for two weeks. Afterward, he returns it and
may then borrow the same book again. And these are counted as borrowing from the library for
two times. The database schema of the library system with sample data is shown below:
STUDENT
StudentID StudentName Address Phone
S01 Chan Tai Man 1 A Street, Tuen Mun 24602460
S02 Charles Lee 2 B Road, Shatin 24542454
S03 May Wong 3 C Way, Tsing Yi 33223322
BOOK
BookID BookName Category Price
B101 Gone with the Wind Fiction 99.00
B202 Introduction to AI Technology 180.00
B304 Big Data Analytics Technology 165.00
BORROW
BookID StudentID BorrowDate ReturnDate
B101 S01 01-MAY-18 14-MAY-18
B101 S01 15-MAY-18
B202 S01 30-APR-18 10-MAY-18
B202 S02 29-APR-18 30-APR-18
B304 S03 30-APR-18