Final Term Lab Manual
Final Term Lab Manual
to Database
Lab Manual Finalterm
American International
University-Bangladesh
Lab 7 (Sub-query)
Exercise:
1. Display all the employees who are earning more than all the managers.
2. Display all the employees who are earning more than any of the managers.
3. Select employee number, job & salaries of all the Analysts who are earning more than any of
the managers.
4. Select all the employees who work in DALLAS.
5. Select department name & location of all the employees working for CLARK.
6. Select all the departmental information for all the managers
7. Display the first maximum salary.
8. Display the second maximum salary.
9. Display the third maximum salary.
10. Display all the managers & clerks who work in Accounts and Marketing departments.
11. Display all the salesmen who are not located at DALLAS.
12. Get all the employees who work in the same departments as of SCOTT.
13. Select all the employees who are earning same as SMITH.
14. Display all the employees who are getting some commission in marketing department where
the employees have joined only on weekdays.
15. Display all the employees who are getting more than the average salaries of all the
employees.
Lab 8 (Joining: Displaying Data from Multiple Tables)
Exercise:
1.Display all the managers & clerks who work in Accounts and Marketing
departments. 2. Display all the salesmen who are not located at DALLAS.
3. Select department name & location of all the employees working for CLARK.
4. Select all the departmental information for all the managers
5.Select all the employees who work in DALLAS.
6.Delete the records from the DEPT table that don’t have matching records in EMP
7.Display all the departmental information for all the existing employees and if a department
has no employees display it as “No employees”.
8.Get all the matching & non-matching records from both the tables.
9.Get only the non-matching records from DEPT table (matching records shouldn’t be selected).
10. Select all the employees name along with their manager names, and if an employee does
not have a manager, display him as “CEO”.
11. Get all the employees who work in the same departments as of SCOTT
12. Display all the employees who have joined before their managers.
13. List all the employees who are earning more than their managers.
14. Fetch all the employees who are earning same salaries.
15. Select all the employees who are earning same as SMITH.Display employee name , his date
of joining, his manager name & his manager's date of joining.
Lab 9 (View)
Exercise
1. Create a view called EMP_VU based on the employee number, employee name, and department
number from the EMP table. Change the heading for the employee name to EMPLOYEE.
7839 KING 10
7698 BLAKE 30
7782 CLARK 10
7566 JONES 20
7654 MARTIN 30
7499 ALLEN 30
7844 TURNER 30
7900 JAMES 30
7521 WARD 30
7902 FORD 20
7369 SMITH 20
7788 SCOTT 20
7876 ADAMS 20
7934 MILLER 10
3. using your view EMP_VU, enter a query to display all employee names and department numbers.
EMPLOYEE DEPTNO
KING 10
BLAKE 30
CLARK 10
JONES 20
MARTIN 30
4. Create a view named DEPT20 that contains the employee number, employee name, and department
number for all employees in department 20. Label the view column EMPLOYEE_ID, EMPLOYEE, and
DEPARTMENT_ID. Do not allow an employee to be reassigned to another department through the
view.
5. Create a view called SALARY_VU based on the employee name, department name, salary, and salary
grade for all employees. Label the columns Employee, Department, Salary, and Grade, respectively.
** Please save the SQL commands in a text file for further use.
Lab 10 (Sequence)
Exercise:
1. Create a sequence to be used with the primary key column of the DEPARTMENT table. The
sequence should start at 60 and have a maximum value of 200. Have your sequence increment
by ten numbers. Name the sequence DEPT_ID_SEQ.
2. Write a script to display the following information about your sequences: sequence name,
maximum value, increment size, and last number.
3. Write an interactive script to insert a row into the DEPARTMENT table. Be sure to use the
sequence that you created for the ID column. Create a customized
prompt to enter the department name. Execute your script. Add two departments named
Education and Administration. Confirm your additions.
Lab 11 (User Control Access)
Exercise:
Suppose you are the DBA for the following schemas. Complete the following task with appropriate
sql command.
Employee
10 Admin E009
20 Sales E002
Products OrderDetais