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)
TEST ONE 10 MARKS TIME: 1.0 HRS
ITU 07301 DATABASE TECHNOLOGIES Tuesday 13th December 2022
ITU 07307 DATABASE SYSTEMS
Answer all questions.
1). Write SQL statement that will add a column named nationality between the sellerName and the DoB columns of the seller table given
that the default nationality is Tanzanian. (1.5 Marks)
ALTER TABLE seller ADD nationality VARCHAR(200) NOT NULL DEFAULT 'Tanzanian' AFTER sellerName;
2). Write SQL statement that list all female sellers in descending order of their names. (1.5 Marks)
SELECT * FROM seller WHERE gender="Female" ORDER BY sellerName DESC;
OR
SELECT * FROM seller WHERE gender !="Male" ORDER BY sellerName DESC;
3). Write SQL DML statement that will remove all data from the sellerMobile table. (1.0 Mark)
DELETE FROM sellerMobile;
4). Write SQL statement to answer the question how many products are measured in either liters (lt) or milliliters (ml) (2.0 Marks)
SELECT COUNT(*) From product WHERE description LIKE "%lt" OR description LIKE "%ml";
5). Using INNER JOIN, whrite SQL statement that will produce a report showing sellerID, sellerName, gender and sellerMobile.
(2.0 Marks)
SELECT S.SellerID, S.sellerName, S.gender, SM.mobileNumber FROM seller S INNER JOIN sellerMobile SM USING(sellerID);
OR
SELECT S.SellerID, S.sellerName, S.gender, SM.mobileNumber FROM seller S INNER JOIN sellerMobile SM ON S.sellerID =
SM.sellerID;
6). Sketch the output of the following query (2.0 Marks)
SELECT sellerID `Namba ya Muuzaji`, sellerName `Jina la Muuzaji`, DoB `Tarehe ya Kuzaliwa`, gender Jinsi FROM seller WHERE sellerID
IN (SELECT sellerID FROM sellerMobile GROUP BY sellerID HAVING COUNT(sellerID)>1) ORDER BY sellerName DESC, sellerID ASC;