You are on page 1of 4

Database Lab Exercise 1

1. Create a table EMPLOYEE with following schema:

(Emp_no, E_name, E_address, E_ph_no, Dept_no, Dept_name, Job_id , Salary)

a. Add a new column; HIREDATE to the existing relation.

b. Change the datatype of JOB_ID from int to varchar.

c. Change the name of column/field Emp_no to E_no.

d. Modify the column width of the job_id field of emp table.

e. Insert aleast 5 rows in the table.

f. Display all the information of EMP table.

g. Display the record of each employee who works in department D10.

h. Display the details of Employee who works in department IS.


Database Lab Exercise 2

1. Consider the following tables namely “DEPARTMENTS” and “EMPLOYEES”


Their schemas are as follows,
Departments (dept_no, dept_ name, dept_location);
Employees (emp_id, emp_name, emp_salary,dept_no);
a. Write SQL statement to create a table for the above schemas?
b. Insert five records for each table.
c. Find out the employee id, names, salaries of all the employees
d. Find the names of the employees who have a salary greater than or equal to
4800
e. List out the employees whose last name is ‘Mesay’.
f. Update the employee salary by 15,000, whose salary is greater than 13,000
years.
g. Delete the employees, whose salary is equals to 5500.

2. WorksOn Database:
emp (eno, ename, bdate, title, salary, dno)
proj (pno, pname, budget, dno)
dept (dno, dname, mgreno)
workson (eno, pno, resp, hours)
a. Create a table for the above schemas?
b. Insert values for each table.
c. Write an SQL query that returns the project number and name for projects
with project number is 10.
d. Write an SQL query that returns the employees (number and name only)
who have a title of ‘PhD'.
3. Write the SQL statement to create the following table
Database Lab Exercise 3
4. Let a University database contains the following:
A teacher has Teacher code (unique), Teacher’s name, Teacher’s address, rank, department.
The teacher teaches courses. Each course has course name, course number(unique), course
credits hours. Students register courses. Each student has student number(unique), name,
major, date of birth, Grade. Courses have sections. Each section has a number(unique) and
location. The following information is given on dependencies.
o A teacher should teach at most 4 courses, and each course could be taught by two
teachers.
o A student may register many courses and each course can be registered by many
students.
o The same course may have more than one section.
A. Design the database using ER-Diagram, taking into consideration all required constraints
(including: Cardinality ratio, multiplicity and Participation) on all relationships?
B. Map the ER-model into a relational model?
C. Write SQL to create a table for the above schemas?
D. Insert at least records for each table?
E. Write the query to display the details of all teachers in descending order of their name?
F. Write the query to display Name, Major and Grade of all students whose grade is 3.99 or
3.89?
G. List all Teachers (number, and name) who work on Information System Department?
H. Write the query to retrieve the average grades from student table?
I. Write the query that retrieve the maximum and minimum grades of student from student
table/
J. Write the query to retrieve the total teachers who work on Computer science department.
K. Write SQL query to display the details of all teachers in descending order of their
department?

You might also like