You are on page 1of 2

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 TWO 10 MARKS TIME: 1.0 HRS

ITU 07301 DATABASE TECHNOLOGIES Tuesday 10th January 2023


ITU 07307 DATABASE SYSTEMS

Answer all the four (4) questions.

Suppose that every time a new student is registered, the system should create a login account for that student. The
login details are stored in the table called users. The table fields and their values are listed here under:

Field Name Field Value


userID registration number in small letters, it is the primary key
password MD5 of the surname in Capital letters
role Student (default)
lastLogin Current date and time (default)

1. Write DDL statement to create the users table using the information on the above table. (2 Marks)
CREATE TABLE users
(
userID VARCHAR(100) NOT NULL PRIMARY KEY,
password TEXT NOT NULL,
role VARCHAR(100) NOT NULL DEFAULT 'student',
lastLogin DATETIME NOT NULL DEFAULT NOW()
);
2. Write a before insert trigger that will create the login details in the users table for every student that will be
registered in the student table. (3 Marks)
DELIMITER !!
CREATE TRIGGER before_student_insert BEFORE INSERT ON student
FOR EACH ROW
BEGIN
INSERT INTO users SET
userID =LCASE(NEW.regNo),
password =MD5(UCASE(NEW.surName));
END!!
DELIMITER ;

3. Write a procedure called getStudentByGender that receive gender value (male or female) and display all details for
all students with that gender value. (3 Marks)
DELIMITER !!
CREATE PROCEDURE getStudentByGender (IN jinsi VARCHAR(10))
BEGIN
SELECT * FROM student WHERE sex=jinsi;
END !!
DELIMITER ;

4. create a view called viewWatanzania that display from the student table, regNo, surName, otherNames, sex and
program for all Tanzania student. Your view should display only 12 records skipping the first 18 records. (2 Marks)
CREATE VIEW viewWatanzania AS
SELECT regNo, surname, otherNames, sex, program FROM student WHERE nationality='Tanzanian' LIMIT 18,12;

You might also like