Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Name: __________________ Student No.

: __________ Class: _______

Section A: Short Questions (80 marks)

Answer ALL questions. Each question carries 20 marks.


Assume Microsoft Access 2013/2016 is used.

A1.
a. Match each key term with its definition by placing the letter of the definition in
the space provided. (Total: 8 marks)
(2 marks each)
Key Terms Answers Definitions

Record ____C____ A. It is a language for querying and updating


databases.
Table ____B____ B. It is a set of records.

Structured ____A____ C. It is a set of fields.


Query
Language
(SQL)
D. It is a format of data that can be stored in a
Data type ____D____ field.

b. Define the following Database Key Terms. (Total: 12 marks)


(4 marks each)
No. Key Terms Definition
1. Database
A database consists (has) one or more tables.

2. Relationship
A relationship shows how two entities share information in the
database.

3. Validation
rule Rules that a user must follow when entering data to ensure
valid data.
A2.
Given the following two tables: (Total: 20 marks)

PRODUCT table
PID Description Cost OrderDate Stock SID
P001 Cheese Sandwich $15.2 16-Jan-2022 37 S03
P002 Seafood Salad $32.6 15-Jan-2022 52 S02
P003 Rice Burger $11.8 18-Jan-2022 90 S01
P004 Cupcake $8.0 20-Jan-2022 71 S01

SHOP table
ShopID SName PhoneNum OnlineShop
S01 Welldone 2233-4666 
S02 NineEleven 3579-0001 
S03 GoodLuck 9091-0123 

a. Fill in the Data Type (Access 2016) for the following fields of the PRODUCT
table and the SHOP table. (4 marks)
Answer:
Field Data Type
Stock Number

OrderDate Date/Time

OnlineShop Yes/No

Cost Currency

b. Write an Input Mask for the field, PhoneNum, which has the format: dd-mmm-
yyyy. (Hint: dd, yyyy are digits, mmm are letters). (3 marks)

Answer:

00-LLL-0000

c. Write a Validation Rule for the field, Stock, so that the input value be greater
than 0 and less than or equal to 150) (2 marks)

Answer:

>0 And <=150 / Between 1 And 150

Page 1 of 12
d. What will be displayed if the following fields and criteria are used in a query in
the MS Access Design View? (3 marks)

Field: PID Description Cost Stock


Table: PRODUCT PRODUCT PRODUCT PRODUCT
Sort: Ascending
Show:    
Criteria: <90
Or:

Answer:
PID Description Cost Stock
P001 Cheese Sandwich $15.2 37

P004 Cupcake $8.0 71

P002 Seafood Salad $32.6 52

e. What will be displayed if the following fields and criteria are used in a query in
the MS Access Design View? (2 marks)

Field: PID Cost SName OnlineShop


Table: PRODUCT PRODUCT SHOP SHOP
Sort: Descendin
g
Show:    
Criteria: >=15
Or: Yes

Answer:
PID Cost SName
P001 $15.2 GoodLuck

P002 $32.6 NineEleven

Page 2 of 12
f. Complete the query in the MS Access Design View below for the PRODUCT
table to display the field, PID, and add a new field called NewCost. The formula
of NewCost is given below: (4 marks)

Formula:
NewCost = Cost * 1.06

The following is the result after the query is run.


PID NewCost
P001 $16.1
P002 $34.6
P003 $12.5
P004 $8.5

What should be put in the MS Access Design View below?

Answer:
Field: PID NewCost: [Cost]*1.06

Table: PRODUCT

Sort:

Show:  
Criteria:

Or:

Page 3 of 12
g. Complete the query in the MS Access Design View below for the PRODUCT
table to display the sum Stock of the products.
(2 marks)

The following is the result after the query is run.


SumOfStock
250

What should be put in the MS Access Design View below?

Answer:
Field: Stock

Table: PRODUCT

Total: SUM

Sort: 

Show:

Criteria:

Or:

Page 4 of 12
A3.
ERD (Total: 20 marks)
a. Besides the Entity component, list ANY TWO main components of an Entity
Relationship Diagram (ERD).
(2 marks)
Answer: Relationship, Attribute, Connecting line, Cardinality
____________________________

____________________________

b. Given the following two tables:


PRODUCT table
PID Description Cost OrderDate Stock SID
P001 Cheese Sandwich $15.2 16-Jan-2022 37 S03
P002 Seafood Salad $32.6 15-Jan-2022 52 S02
P003 Rice Burger $11.8 18-Jan-2022 90 S01
P004 Cupcake $8.0 20-Jan-2022 71 S01

SHOP table
ShopID SName PhoneNum OnlineShop
S01 Welldone 2233-4666 
S02 NineEleven 3579-0001 
S03 GoodLuck 9091-0123 

i. How many attributes (fields) are there in the SHOP table? (2 marks)

Answer: 4

ii. How many records are there in the PRODUCT table? (2 marks)

Answer: 4

iii. Which field should be chosen as the Primary Key for the PRODUCT table?
Give ANY TWO reasons. (4 marks)

Answer:
Primary Key: PID______________________________

Reason 1: Unique Identifier, Not Null, Seldom Change, Most Representative


Reason 2: __________________________________

Page 5 of 12
iv. Which field should be chosen as the Foreign Key for the PRODUCT table?
Give the reason. (4 marks)

Answer:
Foreign Key: SID

Reason: Because it is the primary key of the SHOP table

v. Draw an Entity Relationship Diagram (ERD) for the PRODUCT database for
the following scenarios. You are not required to show the column names in
the entities.

a. Each Product has one and more Shop. Each Shop may have zero or more
PRODUCT(s). (3 marks)

Answer:

b. Each Shop may have zero or more Order (s). Each Order must have
at least one or one Shop. (3 marks)

Answer:

Page 6 of 12
A4.
Given the following 2 tables, write/complete SQL statements below.
(Total: 20 marks)
PRODUCT table
PID Description Cost OrderDate Stock SID
P001 Cheese Sandwich $15.2 16-Jan-2022 37 S03
P002 Seafood Salad $32.6 15-Jan-2022 52 S02
P003 Rice Burger $11.8 18-Jan-2022 90 S01
P004 Cupcake $8.0 20-Jan-2022 71 S01

SHOP table
ShopID SName PhoneNum OnlineShop
S01 Welldone 2233-4666 
S02 NineEleven 3579-0001 
S03 GoodLuck 9091-0123 

a. Display all the records in the PRODUCT table. (3 marks)

Answer:

SELECT *

FROM PRODUCT;

b. Complete the following SQL statement to display ShopID and SName with no
OnlineShop in the SHOP table. (2 marks)

The following is the result after the query is run.


ShopID SName
S01 Welldone

Answer:

SELECT ShopID, SName

FROM SHOP

WHERE OnlineShop = No;

Page 7 of 12
c. Given the SELECT query in the MS Access Design View below: (3 marks)
Field: PID Description Cost
Table: PRODUCT PRODUCT PRODUCT
Sort:
Show:   
Criteria: Like "*oo*"
Or:

Convert the above query to a SQL statement.

Answer:

SELECT PID, Cost

FROM PRODUCT

WHERE Description LIKE “*oo*”;

d. Complete the following SQL statement to display all the records in the
PRODUCT table with the value of SID not equal to "S02" or OrderDate after
15-Jan-2022, in descending order of PID. (4 marks)

The following is the result after the SQL statement is run.

PID Description Cost OrderDate Stock SID


P004 Cupcake $8.0 20-Jan-2022 71 S01
P003 Rice Burger $11.8 18-Jan-2022 90 S01
P001 Cheese $15.2 16-Jan-2022 37 S03
Sandwich

Answer:

SELECT *

FROM PRODUCT

WHERE SID <> “S02”

OR OrderDate > #15-Jan-2022#

ORDER BY PID DESC;

Page 8 of 12
e. Complete the following SQL statement to INSERT the following record into the
PRODUCT table. (3 marks)

PID Description Cost OrderDate Stock SID


P005 Croissant $16.0 17-Jan-2022 101 S02

Answer:

INSERT INTO PRODUCT

VALUES (“P005”, “Croissant”,

16, #17-Jan-2022#, 101, “S02”);

f. Complete the following SQL statement to UPDATE the value of SID to "S01"
for PID equal to "P005" in the PRODUCT table as shown below: (3 marks)
PID Description Cost OrderDate Stock SID
P005 Croissant $16.0 17-Jan-2022 101 S02 S01

Answer:

UPDATE PRODUCT

SET SID = “S01”

WHERE PID = “P005”;

g. Complete the following SQL statement to DELETE the record with the value of
PID equal to "P005" from the PRODUCT table as shown below: (2 marks)
PID Description Cost OrderDate Stock SID
P005 Croissant $16.0 17-Jan-2022 101 S01

Answer:

DELEDTE FROM PRODUCT

WHERE PID = “P005”;

- End of Section A -

Page 9 of 12

You might also like