Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Page 1 of 11

ITP4903
2017/2018 Semester One Main Examination
Suggested Answers

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 2 of 11

Qn. Solution
Q1 Note: Deduct 0.5 mark for any type of errors not specified

(a) Create Table Quotation(


SupID char(2) Not Null,
ItemID char(3) Not Null,
QuotationDate date Not Null,
UnitPrice number(4) Not Null,
DeliveryTime varchar2(20) Null,
Constraint Quotation_pk Primary Key
(SupID, ItemID), -- award the mark only when the primary key attributes are correct
Constraint Quotation_fk1
Foreign Key(SupID)
References Supplier(SupID),
Constraint Quotation_fk2
Foreign Key(ItemID)
References Item(ItemID)
);

(b) Alter Table Item


Add Constraint Item_cc
Check
(ItemSize in ('S','M','L','XL'));

(c) Alter Table Quotation


Add
(Remark varchar2(200)
Null );

(d) Alter Table Quotation


Modify
(QuotationDate
default SYSDATE);

(e) Alter Table Item


Drop Constraint
Item_cc;

(f) CREATE INDEX


ItemSizeIdx

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 3 of 11

ON Item(ItemSize);

(g) CREATE VIEW


SupplierJeans AS
SELECT * FROM Quotation
where ItemID='002';

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 4 of 11

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 5 of 11

Q2 Note: Deduct 0.5 mark for any type of errors not specified

(a) INSERT INTO Quotation VALUES


( '19', '003', '20-MAR-17', 60, NULL); '
—OR
INSERT INTO Quotation(SupID, ItemID, QuotationDate, UnitPrice) VALUES
( '19', '003', '20-MAR-17', 60);
(b)
UPDATE Quotation
SET UnitPrice = UnitPrice * 0.9
WHERE ItemID = '002'
AND SupID = '01';
(c)
DELETE FROM Quotation
WHERE QuotationDate >= '01-APR-17';
(d)
SELECT DISTINCT SupName
FROM Quotation, Supplier
WHERE Quotation.SupID = Supplier.SupID
AND
(
SupPhone LIKE '%333'
OR ItemID != '005'
);
(e)
SELECT ItemID, MIN(UnitPrice)
FROM Quotation
GROUP BY ItemID
HAVING COUNT(*) >=2
ORDER BY MIN(UnitPrice);
(f)
SELECT SupID, ItemID, QuotationDate
FROM Quotation
WHERE DeliveryTime IS NOT NULL;
(g)
SELECT SupName, Item.ItemID, itemName, Color, UnitPrice
FROM Supplier, Item, Quotation
WHERE Quotation.SupID = Supplier.SupID
AND Quotation.ItemID = Item.ItemID
AND Color IN ('White', 'Blue')

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 6 of 11

AND ItemName = 'T-shirt';

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 7 of 11

Q3(a) The medication relation has data redundancy and data redundancy will cause update
anomalies.

(b) Insertion Anomalies.


To insert a new patient whose doctor is D002, the doctor name inserted must be
identical and consistently with the name of D002 in other tuples. Otherwise, the data
will become inconsistent.

Deletion Anomalies.
To delete the tuple for patient P0022, the details related to doctor D015 Betty (or
medicine M012 Crestor) are also lost.

Modification Anomalies.
To change the doctor name of D002, the change must be carried out on ALL tuples
related to D002. Otherwise, the data will become inconsistent.

TWeight
(c) Because it is a derived attribute and can be obtained by UWeight x Dosage

(d)(i) UNF:
Medication(PatNo, PatName, DocID, DocName, MedID, MedName,
UWeight, Dosage)
(ii) 1NF: (removing repeating group: MedID, MedName, UWeight, Dosage)
Patient(PatNo, PatName, DocID, DocName)
Medication(PatNo, MedID, MedName, UWeight, Dosage)

2NF : (removing partial dependency: MedID  MedName, UWeight)


Patient(PatNo, PatName, DocID, DocName)
Medication(PatNo, MedID, Dosage)
Medicine(MedID, MedName, UWeight)

3NF: (removing transitive dependency: PatNo  DocID  DocName)


Patient(PatNo, PatName, DocID)
Medication(PatNo, MedID, Dosage)
Medicine(MedID, MedName, UWeight)
Doctor(DocID, DocName)

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 8 of 11

(e)

Medication

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 9 of 11

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 10 of 11

Q4(a)(i) Candidate key: An attribute, or minimal set of attributes, that uniquely identifies a
tuple within a relation.
Example: (Any one of the followings)
TourGuideID or
Mobile or
TICLicense

(ii) Alternate key: Candidate keys that are not selected to be primary key.
Example:
TICLicense or Mobile

(b)(i) Attribute Domain: Specifies the set of allowable values associated with attribute.

(ii) Any 4 of the followings, each 0.5 mark, max. 2 marks:


Name Type Length Min Max Description
TourCode alphanumeric 7 TC00001 TC99999 Unique tour number

(iii) (1) Degree: the number of attributes in a relation.

(2) In TOUR relation, degree is 4

(c)(i) The primary key attribute TourGuideID in the TOURGUIDE relation


cannot be null and should not be repeated.

(ii) TourGuideID is the foreign key of in TOUR relation and its value should either
match the existing values of the TourGuideID in the relation TOURGUIDE or be
wholly null.

(iii) TOURGUIDE.TourGuideID is referenced by TOUR.TourGuideID, so the


TOURGUIDE relation is the parent relation of TOUR relation. Referential
Integrity rule does not allow it from removal.

(d)
Any two of the followings: (1 mark each, max. 2 marks)
 Program-Data Dependence
 Data Redundancy
 Limited Data Sharing
 Lengthy Development Times
 Excessive Program Maintenance
(accept other reasonable answers)

(e) Any one of the following: (2 marks each)


 External level describes that part of database that is relevant to a particular user.
Internal level describes how the data is stored in the database

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)
Page 11 of 11

or
 External level is the users’ view of the database and
Internal level is the physical representation of the database on the computer

(accept other reasonable answers)


***END ***

Database Principles Main Examination Semester 1 (2017/2018)


(ITP4903)

You might also like