You are on page 1of 8

Restricted, Non-Sensitive

SECURITY CLASSIFICATION: Official (CLOSED), NON-SENSITIVE ST1501

SINGAPORE POLYTECHNIC

2022/2023 SEMESTER TWO TEST

DIPLOMA IN INFORMATION TECHNOLOGY


SECOND YEAR FULL TIME

DATA ENGINEERING Time allowed: 1.5 Hours

Instruction to Candidates

1. This paper comprises 4 questions and SQL Commands Reference Sheet.

2. This test paper consists of 8 pages (inclusive of cover page).

3. Answer ALL questions.

4. All answers should be written in the answer booklet.

5. Start each question on a new page.

/S2 Page 1
Restricted, Non-Sensitive

SECURITY CLASSIFICATION: Official (CLOSED), NON-SENSITIVE ST1501

SQL Commands Reference Sheet

Format of a simple query statement SELECT <List of columns>


FROM<Table>

Format of a grouped query statement SELECT <List of Grouping Columns>,


<Aggregate Function>
FROM <Table>
WHERE <Row Selection Criteria>
GROUP BY <List of Grouping Columns>
HAVING <Group Selection Criteria>

Format of CREATE TABLE CREATE TABLE <table name> (


statement <column definition list>
PRIMARY KEY <column name list>,
FOREIGN KEY <column name list>
REFERENCES <Table Name>)

Format of the INSERT statement INSERT INTO <Table Name><


(Column List) >
Values <Column Value List>

Format of DROP table from database DROP TABLE <table name>


statement
Format of DELETE Rows statement DELETE FROM <table name>
[<WHERE Row selection criteria>]

Format of UPDATE Rows statement UPDATE <Table Name>


SET ColumnNamel = ColumnValuel
[,ColumnName2 = ColumnV.alue2 ... ]
[WHERE Row selection criteria]

Format of ALTER table to specify ALTER TABLE <table name>


new foreign key after table is created ADD FOREIGN KEY
(<foreign key attribute name list>)
REFERENCES <Table Name>(< Primary key
attribute name list>)

Format of CREATE VIEW statement CREATE VIEW <View Name>


AS SELECT <List of columns>
FROM <Table>

/S2 Page 2
Restricted, Non-Sensitive

SECURITY CLASSIFICATION: Official (CLOSED), NON-SENSITIVE ST1501

1. The following relations show some members’ details, facilities description and rentals of
facilities by members in Jessie Country Club (JCC).

Member
MemberID Name Status Gender
A12345 Alexis Soh Wee Beng Ord M
A78655 Catherine Seah Ai Ord F
P21090 John Pereira Pri M
P34672 Sally Wee Pri F
P10989 John Pereira Ord M
P98981 Jenny Chua NULL F

Legend: The status of the member in the Club.


NULL for membership < 1 year.
Ordinary(Ord) for membership between 1 and 5 years
Privileged(Pri) for membership > 5 years

Facility
FacilityID Description
E7865 Barbeque Pit
R1234 Karaoke Room
S6751 Badminton Court
S9879 Tennis Court

Rental
MemberID FacilityID Rental Date TimeStart TimeEnd
A12345 R1234 40.50 10/12/2022 1100 1300
A12345 R1234 40.50 11/7/2022 1100 1300
A78655 E7865 60.00 10/12/2022 1900 2200
P21090 E7865 50.00 7/6/2022 1900 2200
P34672 S6751 20.50 12/10/2022 1200 1300
A12345 R1234 40.50 10/12/2022 1500 1800

Note: Assume all columns can accept NULL except those columns that belong to the
Primary key

(a) Suggest an appropriate Primary Key for the Rental relation. (4 marks)

(b) The foreign keys and their referenced relations in Rental are indicated as follows.
Indicate with the help of line number, which statement is not permissible and state the
reason and the rule violated in the table provided. (2 marks)

Line Number Rule violated Reason

/S2 Page 3
Restricted, Non-Sensitive

SECURITY CLASSIFICATION: Official (CLOSED), NON-SENSITIVE ST1501

Statement Line Number


Foreign key (MemberID) references Member(MemberID) 1
On delete set Null 2
On update cascade, 3
Foreign key (FacilityID) references Facility(FacilityID) 4
On update cascade 5

(c) Based on line numbers 4 and 5 from 1(b), indicate if the following statements is True
or False.

i) If a particular MemberID is updated, the corresponding foreign key is also


updated with the same value. (1 mark)

ii) If a particular FacilityID is deleted, the corresponding foreign key is also


deleted. (1 mark)

iii) If a particular FacilityID is deleted, the corresponding foreign key is not deleted.
(1 mark)

iv) If a particular FacilityID is updated, the corresponding foreign key is also


updated with the same value. (1 mark)

v) If a particular FacilityID is deleted, the corresponding foreign key is updated


to NULL (1 mark)

(d) The following rows are to be added into the Rental relation.

P34672 S2034 10.50 12/1/2022 1200 1300 Row 1


A10001 R1234 40.50 10/12/2022 1100 1300 Row 2
P21090 E7865 50.00 7/12/2022 1900 2200 Row 3
NULL NULL NULL NULL NULL NULL Row 4

Indicate True or False in the following table and the reason if your choice is False.

Row Can be added? Reason


1 True/False
2 True/False
3 True/False
4 True/False
( 5 marks)

(e) The following attribute(s) is/are chosen as Candidate Keys(CK) and Primary Key (PK)
for Member relation. Indicate if the choices are valid and the reason if your choice is
No.

/S2 Page 4
Restricted, Non-Sensitive

SECURITY CLASSIFICATION: Official (CLOSED), NON-SENSITIVE ST1501

Attribute(s) Key Choice Reason


MemberID, Name PK Yes/No
Name PK Yes/No
MemberID, Status CK Yes/No
Name, Gender CK Yes/No
(4 marks)

2. A collection of landed property leases is shown below. Assuming that a client rents a given
property only once and cannot rent more than one property at any one time. Rent is
computed on a monthly basis.

ClientRental
ClientNo CName PropNo Paddress RentStart RentFinish Rent OwnerNo OName

CR76 Justin PG4 26 Upper 1-Jul-2001 31-Aug-2001 8000 CO40 Seth


Seah Bukit Wong
Road

PG16 14 Nassim 1-Sep-2001 1-Sep-2002 20000 C093 Tony


Road Shaw

CR56 Aline PG4 26 Upper 1-Sep-1999 10-Jun-2000 8000 CO40 Seth


Stewart Bukit Wong
Road

PG36 1 Siglap 10-Oct-2000 1-Dec-2001 4000 C093 Gerald


Road Lim

PG16 14 Nassim 1-Nov2002 10-Aug-2003 20000 C093 Tony


Road Shaw

(a) Express the above table in 1NF in relational heading format. Underline the Primary
Key (2 marks)

(b) i) Give 2 examples of an insert anomaly (4 marks)

ii) Give 1 example of a delete anomaly (2 marks)

(c) List all the functional dependencies from the 1NF relation. (6 marks)

(d) Convert the table in 1NF into 2NF in relational heading format. Underline all Primary
Keys. (3 marks)
(e) List all the transitive dependencies from the 2NF relations (2 marks)

(f) Convert the tables in 2NF into 3NF in relational heading format. Underline all Primary
Keys with bold lines and all Foreign Keys with dotted lines. (6 marks)

/S2 Page 5
Restricted, Non-Sensitive

SECURITY CLASSIFICATION: Official (CLOSED), NON-SENSITIVE ST1501

3. Unpopular is an online stationery shopping platform that is selling different types of


products to customers in Singapore. The following tables list the information of its
products. Note: datatype for Points_earned in the Customers tables is Integer.
Items
Item_ID Description Unit_price Category UPC
A001 Canvas Panel 18 Art and Craft 03600029145
A002 Glitter Glue Pen 4.5 Art and Craft 03600029146
A003 Cartridge Pad – Fine 5.75 Art and Craft 03600029147
S001 Pen Blue 1.5 Stationery 03600029148
S002 Pen Black 1.4 Stationery 03600029149
S003 Faber Castell Pen Blue 3.5 Stationery 03600029150
S004 Multicolor Pen Set 7 Stationery 03600029151
S005 Pen Holder 15.2 Stationery 03600029152
T001 Chips 7.5 Tidbits 03600029153
T002 Cheese Crackers 5.5 Tidbits 03600029154

Customers Order_Items
Customer_ID Name Points_earned Order_Number Item_ID Quantity
101 Jeffery 300 1 A001 1
102 Gabriel 50 2 A001 3
103 Bryan 50 2 S001 4
104 Richie 600 2 S002 2
105 Elvis 200 3 S003 4
106 Jonas 500 4 S005 1
107 Justin NULL 5 S004 5
108 Zaki NULL 6 S002 5
109 Uwan NULL 6 T001 1
7 A001 2
Orders
Order_Number Order_Date Customer_ID
1 2019-02-01 101
2 2019-04-15 101
3 2019-02-01 105
4 2019-04-24 104
5 2019-05-10 104
6 2019-05-10 105
7 2019-10-15 106
(a) Assuming the Customers, Items and Orders tables are created, write an SQL statement
to create the Order_Items table specifying all the primary keys and foreign keys.
Ignore referential actions. (5 marks)

/S2 Page 6
Restricted, Non-Sensitive

SECURITY CLASSIFICATION: Official (CLOSED), NON-SENSITIVE ST1501

(b) Write an SQL statement to list the Customer’s ID and their points earned. Those
customers with unknown points earned should be indicated with ‘No points earned’.
The following is the expected output of the query. (7 marks)

(c) Write an SQL statement to list the orders and their respective total cost ordered. The
following is the expected output of the query. (8 marks)

(d) Write an SQL statement to list items that do not contain ‘Pen’ ordered by the item
description in an ascending order. The following is the expected output of the query.
(5 marks)

/S2 Page 7
Restricted, Non-Sensitive

SECURITY CLASSIFICATION: Official (CLOSED), NON-SENSITIVE ST1501

4. TookTock is a social network company that develops their products for mass
adoption. They are setting up a database to manage their human resource and
property access system. They will be using the following business rules.

• Each personnel is uniquely identified by a PersonId.


• All personnel can either be an employee or a contractor.
• An employee’s designation is recorded.
• A contractor’s company is also recorded.
• Every visit to the office will be logged.
• A visit is uniquely identified by the PersonID and the timestamp of visit.
• A person can make several visits.
• Access is a way for us to differentiate people into groups where they have
different access levels during their visits.
• An access is uniquely identified by the Level (An integer).
• A location will have its own access level classification,
• An access level can be issued to many people.
• A particular location accessed by a person will have its timestamp recorded
• A visit records the location, in order to identify which area is being accessed.
• An employee can apply for off-time several times.
• Each off-time must be approved by a manager.
• An off-time only applies for a single day and the date is kept.
• An employee must always have a manager.
• An employee does not necessarily manage employees.

Draw a single Entity Relationship Diagram (ERD) to model the data requirements for the
TookTock database. You must adhere to the following requirements:

• Your entities in the ERD should include the primary keys and its attributes.
You must underline these primary keys. Composite primary keys are allowed.
The complete Primary Key will have to be shown in the diagram for weak entity types.
• Attributes for subtypes are required to be shown
• You must draw (in crow-foot notation) the cardinalities and participation
constraints of the relationships.
• If there are any, you should resolve M:N relations.

(30 marks)
---End of Paper---

/S2 Page 8

You might also like