You are on page 1of 4

NATIONAL INSTITUTE OF TRANSPORT

DEPARTMENT OF COMPUTING AND COMMUNICATION TECHNOLOGY


HIGHER DIPLOMA TWO IN INFORMATION TECHNOLOGY (HDIT-2)
HIGHER DIPLOMA TWO IN COMPUTER SCIENCE (HDCS-2)
FIRST SEMESTER EXAMINATION; 2016/2017

MODULE NAME: DATABASE TECHNOLOGIES TIME: 3 HRS


MODULE CODE: ITU 07301 THURSDAY 25TH, MAY 2017

Answer all Questions in Section A and ONLY ONE Question in Section B

The following four tables represent a current state of a database called sellingCompany used by a small
scaled business firm to keep records of its activity. They can be used in answering the examination
questions whenever necessary.

Page 1 of 4
SECTION A
QUESTION ONE (25 Marks)
a). Differentiate DDL SQL from DML SQL.
b). With respect to the database tables, what are the uses of
i) Primary Key ii). Foreign Key
c). Write SQL statement to change the console delimiter to two dollar sign ($$).
d). Write SQL statement to display structure of the product table and SQL statement to show the create
table statement of the seller table.
e). Write SQL statement that will remove the column called gender from the seller table.
f). Write SQL statement that will add a column named saleVAT in the saleRecords table. That column
should be placed before saleDate. The columns will hold data like those in the salePrice column with
a default value of 0.00.
g). Write SQL statement that will insert the first two rows shown in the sellerMobile table at once.
h). Write SQL statement to truncate the table product table.
i). Write SQL statement to rename the table sellerMobile to simuYaMuuzaji.

Page 2 of 4
QUESTION TWO (25 Marks)
a). What will be the effect of writing and update/delete statement without including a where clause?
b). Write SQL statement that list all products details for the product that are measured either in millilitres
(ml) or grams (gm).
c). Write SQL statement that will change the description of product with id PD0006 from PILAU
MASALAMA 100gm to PILAU MASALA 100gm.
d). Count all records found in the seller table.
e). Write SQL statement to delete the record with sellerID SD010 from the sellerMobile table.
f). Write SQL statement to list the second fifty (50) sales record (from saleRecords table) for all products
with productID equal to PD0002 or PD0022 or PD0012 or PD0014 or PD0011 or PD0015 or
PD0080, PD0030 or PD0031 or PD0063.
g). Write SQL statement that will answer the question how many sellers have mobile phone?

QUESTION THREE (25 Marks)


a). Draw a view showing the output of the query below
SELECT s.sellerID AS 'Jina la Muuzaji', s.DoB AS 'Tarehe ya Kuzaliwa', sm.mobileNumber AS
'Namba ya Simu' FROM seller AS s LEFT JOIN sellerMobile AS sm ON s.sellerID = sm.sellerID
WHERE s.gender = 'female';

b). Using a right join, produce a report showing sellerID, sellerName, productID, description and total
quantity sold (for each product) by each seller in ascending order of sellerID.
c). Using where clause, produce a report showing saleID, sellerName, description and saleQuantity for
the first 350 sale records (found in saleRecords table). Sort your output in descending order of their
saleDate.
d). List all details in the product table for all items that were sold (salePrice) at the price of at least 750.75
in ascending order of their proposedPrice.

SECTION B
Page 3 of 4
Answer Only One Question
QUESTION FOUR (25 Marks)
a). How does a stored procedure differ from trigger in terms of their invocation.
b). Create a procedure named getProductDetails that receive productID and return its description and
proposedPrice.
c). Create a procedure named saleLevel that receive saleID and uses if….elseif return the level of sales
based on the three categories shown in the table below where sale total is the product of saleQuantity and
salePrice of that sale.
Level of sales
Sale Total (saleQuantity x salePrice) Sale Level
Less than 50000.00 Normal Sale
Between 50000.00 and 150000.00 inclusively Medium Sale
Above 150000.00 Super Sale

QUESTION FIVE (25 Marks)


It was agreed by the business manager that since products price changes frequently, there should be
a records of all such changes in the database. As a result, a table called priceLog should be create
and used to record any change in price of a particular product. The table will record the productID,
unitPrice and changeDate. The table’s primary key should be changeID which is an auto increment
field. The changeDate should be added automatically by the system using date function.
a). Using appropriate data type, create the table priceLog with InnoDB storage engine
b). Create a trigger on product table that will log changes into the priceLog table in case of any update
occurs in the product table.

Page 4 of 4

You might also like