You are on page 1of 4

a.

Normalize the below database table to the 2NF (5mark

Stu_ID Proj_ID Stu_Name Proj_Name


1 201 MOHAMED MYSQL
2 309 HASSAN NODE JS
3 140 FATUMA PHP
4 520 MUSTAFA PYTHON

Table 1: Student

Stu_ID (PK)

Stu_Name

Table 2: Project

Proj_ID (PK)

Proj_Name Stu_ID (FK)

b. Below is a database table named ‘EMPLOYESS ‘. Use it to answer the following


questions
+------+----------+---------+----------+
|SSN | EMP_NAME | EMP_AGE |EMP_SALARY|
+------+----------+---------+----------+
| 112 | hassan | 11 | 5000.00 |
| 113 | Peter | 24 | 7450.00 |
| 114 | David | 33 | 3344.00 |
| 115 | Benzema | 29 | 2288.00 |
| 116 | hani | 65 | 1400.00 |
| 117 | saadia | 24 | 1900.00 |
| 118 | aman | 35 | 16200.00 |
+------+----------+---------+----------+
Write an SQL query to;
i. Fetch the name of the those employees who are more than 23 years
old

SELECT EMP_NAME FROM EMPLOYEES WHERE EMP_AGE > 23;

ii. Fetch all the details of employees having salary greater than 5000
SELECT * FROM EMPLOYEES WHERE EMP_SALARY > 5000;

iii. Find out the SSN of employee “aman”.

SELECT SSN FROM EMPLOYEES WHERE EMP_NAME = 'aman';

c. A table called Employee has the following fields: Employee ID, First Name,
Second Name, Date of Birth, Gender, Marital Status, Religion and Salary. Write
SQL statements to do each of the following.
i.) Retrieve all records [include all fields] from the table. (2marks)

SELECT * FROM Employee;

ii.) Retrieve the Employee ID, First Name, Second Name, Date of Birth, Gender
and Marital Status.(3 marks)

SELECT Employee_ID, First_Name, Second_Name, Date_of_Birth, Gender,


Marital_Status FROM Employee;

d. Write SQL commands to create a database name Umma_university and a table called
student_table then insert the following data; (15mks)

Create the database

CREATE DATABASE Umma_university;

Create the table


CREATE TABLE students (

Roll_no INT PRIMARY KEY,

Student_name VARCHAR(50),

Age INT,

Branch_id INT
);
Insert the data

INSERT INTO students (Roll_no, Student_name, Age, Branch_id)

VALUES (1, 'Andrew', 18, 10);

INSERT INTO students (Roll_no, Student_name, Age, Branch_id)

VALUES (2, 'Angel', 19, 10);

INSERT INTO students (Roll_no, Student_name, Age, Branch_id)

VALUES (3, 'Priya', 20, 10);

INSERT INTO students (Roll_no, Student_name, Age, Branch_id)

VALUES (4, 'Analisa', 21, 11);

INSERT INTO students (Roll_no, Student_name, Age, Branch_id)

VALUES (5, 'Anna', 21, 12);

You might also like