DBMS Lab Manual Final City Midnapore
DBMS Lab Manual Final City Midnapore
DBMS Lab Manual Final City Midnapore
EMPLOYEE Schema
Field Type NULL KEY DEFAUL
Eno Char(3) NO PRI T
NIL
Ename Varchar(50) NO NIL
Job_type Varchar(50) NO NIL
Manager Char(3) YES FK NIL
Hire_date Date NO NIL
Dno Integer YES FK NIL
Commission Decimal(10,2) YES NIL
Salary Decimal(7,2) NO NIL
DEPARTMENT Schema
Query List
1. Query to display Employee Name, Job, Hire Date, Employee Number; for each
employee with the Employee Number appearing first.
4. Query to display all the data from the Employee Table. Separate each Column by
a comma and name the said column as THE_OUTPUT.
5. Query to display the Employee Name and Salary of all the employees earning
more than
$2850.
6. Query to display Employee Name and Department Number for the Employee No=
7900.
7. Query to display Employee Name and Salary for all employees whose salary is
not in the range of $1500 and $2850.
8. Query to display Employee Name and Department No. of all the employees in
Dept 10 and Dept 30 in the alphabetical order by name.
9. Query to display Name and Hire Date of every Employee who was hired in 1981.
10. Query to display Name and Job of all employees who don‘t have a current Manager.
11. Query to display the Name, Salary and Commission for all the employees who
earn commission. Sort the data in descending order of Salary and Commission.
12. Query to display Name of all the employees where the third letter of their name is
‗A‘.
13. Query to display Name of all employees either have two ‗R‘s or have two ‗A‘s in
their name and are either in Dept No = 30 or their Manger‘s Employee No = 7788.
14. Query to display Name, Salary and Commission for all employees whose
Commission Amount is 14 greater than their Salary increased by 5%.
16. Query to display Name, Hire Date and Salary Review Date which is the 1st
Monday after six months of employment.
17. Query to display Name and calculate the number of months between today and
the date each employee was hired.
18. Query to display the following for each employee <E-Name> earns < Salary>
monthly but wants < 3 * Current Salary >. Label the Column as Dream Salary.
19. Query to display Name with the 1st letter capitalized and all other letter lower
case and
length of their name of all the employees whose name starts with ‗J‘, ‘A‘ and ‗M‘.
20. Query to display Name, Hire Date and Day of the week on which the employee
started.
21. Query to display Name, Department Name and Department No for all the
employees.
22. Query to display Unique Listing of all Jobs that are in Department # 30.
23. Query to display Name, Dept Name of all employees who have an ‗ A‘ in their
name.
24. Query to display Name, Job, Department No. and Department Name for all the
employees working at the Dallas location.
25. Query to display Name and Employee no. Along with their Manger‘s Name and
the Manager‘s employee no; along with the Employees‘ Name who do not have a
Manager.
26. Query to display Name, Dept No. and Salary of any employee whose department
No. and salary matches both the department no. and the salary of any employee
who earns a commission.
27. Query to display Name and Salaries represented by asterisks, where each asterisk
(*) signifies $100.
28. Query to display the Highest, Lowest, Sum and Average Salaries of all the
employees
29. Query to display the number of employees performing the same Job type functions.
30. Query to display the no. of managers without listing their names.
31. Query to display the Department Name, Location Name, No. of Employees and
the average salary for all employees in that department.
32. Query to display Name and Hire Date for all employees in the same dept. as Blake.
33. Query to display the Employee No. and Name for all employees who earn more
than the average salary.
34. Query to display Employee Number and Name for all employees who work in a
department
with any employee whose name contains a ‗T‘.
35. Query to display the names and salaries of all employees who report to King.
36. Query to display the department no, name and job for all employees in the Sales
department.
Table Creation
SQL> create table department(Dno number(10), Dname varchar2(20), Location
varchar2(20), primary key (Dno));
SQL> create table employee(Eno char(3), Ename varchar2(20), Job_type
varchar2(20), Manager char(3), Hire_date date, Dno number(10), Commission
decimal(10, 2), Salary decimal(7,2), primary key(Eno), constraint Dno foreign
key (Dno) references department (Dno));
Table Description
SQL> desc department
Name Null? Type
----------------------------------------- -------- ----------------------------
DNO NOT NULL NUMBER(10)
DNAME VARCHAR2(20)
LOCATION VARCHAR2(20)
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> select * from department;
Employee Table
SQL> insert into employee values('736', 'Smith', 'Clerk', '790',
to_date('17/12/1981','dd/mm/yyyy'), 20, 0.00, 1000.00);
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> commit;
Commit complete.
1 row created.
1 row created.
SQL> insert into employee values('790', 'James', 'Clerk', '769',
to_date('03/12/1981','dd/mm/yyyy'), 30, 0.00, 950.00);
1 row created.
1 row created.
1 row created.
SQL> select * from employee;
14 rows selected.
1. Query to display Employee Name, Job, Hire Date, Employee
Number; for each employee with the Employee Number appearing
first.
SQL> select Eno, Ename, Job_type, Hire_date from employee;
JOB_TYPE
--------------------
Analyst
Clerk
Manager
President
Sales_man
NAME_JOB
------------------------------------------
Scott, Analyst
Smith, Clerk
Allan, Sales_man
Ward, Sales_man
Jones, Manager
Martin, Sales_man
Blake, Manager
Clark, Manager
King, President
Turner, Sales_man
Adams, Clerk
Miller, Clerk
James, Clerk
Ford, Analyst
14 rows selected.
4. Query to display all the data from the Employee Table. Separate each
Column by a comma and name the said column as THE_OUTPUT.
SQL> select Eno||', '||Ename||', '||Job_type||', '||Manager||', '||Hire_date||', '||
Dno||', '||Commission||', '||Salary from employee ;
ENO||','||ENAME||','||JOB_TYPE||','||MANAGER||','||HIRE_DATE||','||
DNO||','||COM
--------------------------------------------------------------------------------
788, Scott, Analyst, 756, 09-DEC-82, 20, 0, 2850
736, Smith, Clerk, 790, 17-DEC-81, 20, 0, 1000
749, Allan, Sales_man, 769, 20-FEB-81, 30, 300, 2000
752, Ward, Sales_man, 769, 22-FEB-81, 30, 500, 1300
756, Jones, Manager, 783, 02-APR-81, 20, 0, 2300
765, Martin, Sales_man, 784, 22-APR-81, 30, 1400, 1250
769, Blake, Manager, 783, 01-MAY-81, 30, 0, 2870
778, Clark, Manager, 783, 09-JUN-81, 10, 0, 2900
783, King, President, , 17-NOV-81, 10, 0, 2950
784, Turner, Sales_man, 769, 08-SEP-81, 30, 0, 1450
787, Adams, Clerk, 778, 12-JAN-83, 20, 0, 1150
793, Miller, Clerk, 788, 23-JAN-82, 40, 0, 1300
790, James, Clerk, 769, 03-DEC-81, 30, 0, 950
792, Ford, Analyst, 756, 03-DEC-81, 20, 0, 2600
14 rows selected.
5. Query to display the Employee Name and Salary of all the employees
earning more than $2850.
SQL> select Ename, salary from employee where
(salary+commission)>2850;
ENAME SALARY
-------------------- ----------
Blake 2870
Clark 2900
King 2950
ENAME DNO
-------------------- ----------
James 30
7. Query to display Employee Name and Salary for all employees whose
salary is not in the range of $1500 and $2850.
SQL> select Ename, salary from employee where salary not between
1500 and 2850;
ENAME SALARY
-------------------- ----------
Smith 1000
Ward 1300
Martin 1250
Blake 2870
Clark 2900
King 2950
Turner 1450
Adams 1150
Miller 1300
James 950
10 rows selected.
ENAME DNO
-------------------- ----------
Allan 30
Blake 30
Clark 10
James 30
King 10
Martin 30
Turner 30
Ward 30
8 rows selected.
9. Query to display Name and Hire Date of every Employee who was
hired in 1981.
ENAME HIRE_DATE
-------------------- ---------
Smith 17-DEC-81
Allan 20-FEB-81
Ward 22-FEB-81
Jones 02-APR-81
Martin 22-APR-81
Blake 01-MAY-81
Clark 09-JUN-81
King 17-NOV-81
Turner 08-SEP-81
James 03-DEC-81
Ford 03-DEC-81
11 rows selected.
10.Query to display Name and Job of all employees who don’t have a
current Manager.
SQL> select Ename, Job_type from employee where Manager is NULL;
ENAME JOB_TYPE
-------------------- --------------------
King President
11.Query to display the Name, Salary and Commission for all the
employees who earn commission. Sort the data in descending order
of Salary and Commission.
12.Query to display Name of all the employees where the third letter of
their name is ‘a’.
ENAME
--------------------
Blake
Clark
Adams
13.Query to display Name of all employees either have two ‘r’s or have
two ‘a’s in their name and are either in Dept No = 30 or their
Manger’s Employee No = 778.
SQL> select Ename, Dno, Manager from employee where Ename like
'%a%a' or Ename like '%r%r' and Dno=30 or Manager='778';
SYSDATE
---------
25-JUN-23
16.Query to display Name, Hire Date and Salary Review Date which is
the 1st Monday after six months of employment.
ENAME HIRE_DATE
-------------------- ---------
REVIEW
----------------------------------------------------
Scott 09-DEC-82
Monday, the Thirteenth of June, 1983
Smith 17-DEC-81
Monday, the Twenty-First of June, 1982
Allan 20-FEB-81
Monday, the Twenty-Fourth of August, 1981
ENAME HIRE_DATE
-------------------- ---------
REVIEW
----------------------------------------------------
Ward 22-FEB-81
Monday, the Twenty-Fourth of August, 1981
Jones 02-APR-81
Monday, the Fifth of October, 1981
Martin 22-APR-81
Monday, the Twenty-Sixth of October, 1981
ENAME HIRE_DATE
-------------------- ---------
REVIEW
----------------------------------------------------
Blake 01-MAY-81
Monday, the Second of November, 1981
Clark 09-JUN-81
Monday, the Fourteenth of December, 1981
King 17-NOV-81
Monday, the Twenty-Fourth of May, 1982
ENAME HIRE_DATE
-------------------- ---------
REVIEW
----------------------------------------------------
Turner 08-SEP-81
Monday, the Fifteenth of March, 1982
Adams 12-JAN-83
Monday, the Eighteenth of July, 1983
Miller 23-JAN-82
Monday, the Twenty-Sixth of July, 1982
ENAME HIRE_DATE
-------------------- ---------
REVIEW
----------------------------------------------------
James 03-DEC-81
Monday, the Seventh of June, 1982
Ford 03-DEC-81
Monday, the Seventh of June, 1982
14 rows selected.
ENAME Months_Worked
-------------------- -------------
Scott 487
Smith 498
Allan 508
Ward 508
Jones 507
Martin 506
Blake 506
Clark 505
King 499
Turner 502
Adams 485
Miller 497
James 499
Ford 499
14 rows selected.
Dream Salary
--------------------------------------------------------------------------------
Scott earns $2850 monthly but wants $8550
Smith earns $1000 monthly but wants $3000
Allan earns $2000 monthly but wants $6000
Ward earns $1300 monthly but wants $3900
Jones earns $2300 monthly but wants $6900
Martin earns $1250 monthly but wants $3750
Blake earns $2870 monthly but wants $8610
Clark earns $2900 monthly but wants $8700
King earns $2950 monthly but wants $8850
Turner earns $1450 monthly but wants $4350
Adams earns $1150 monthly but wants $3450
Miller earns $1300 monthly but wants $3900
James earns $950 monthly but wants $2850
Ford earns $2600 monthly but wants $7800
14 rows selected.
19.Query to display Name with the 1st letter capitalized and all other
letter lower case and length of their name of all the employees whose
name starts with ‘J’, ’A’ and ‘M’.
SQL> select initcap(Ename) "Name", length(Ename) "Length of Name"
from employee where Ename like 'J%' or Ename like 'A%'
or Ename like 'M%' order by Ename;
6 rows selected.
20.Query to display Name, Hire Date and Day of the week on which the
employee started.
14 rows selected.
21.Query to display Name, Department Name and Department No for
all the employees.
14 rows selected.
JOB_TYPE
--------------------
Manager
Clerk
Sales_man
23.Query to display Name, Dept Name of all employees who have an ‘a’
in their name.
SQL> select employee.Ename,department.Dname from
employee,department where employee.Ename like '%a%' and
employee.Dno=department.Dno;
ENAME DNAME
-------------------- --------------------
Allan Sales
Ward Sales
Martin Sales
Blake Sales
Clark Accounting
Adams Research
James Sales
7 rows selected.
25.Query to display Name and Employee no. Along with their Manger’s
Name and the Manager’s employee no; along with the Employees’
Name who do not have a Manager.
20 rows selected.
26.Query to display Name, Dept No. And Salary of any employee whose
department No. And salary matches both the department no. And the
salary of any employee who earns a commission.
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Scott
*
Smith
*
Allan
*
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Ward
*
Jones
*
Martin
*
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Blake
*
Clark
*
King
*
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Turner
*
Adams
*
Miller
*
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
James
*
Ford
*
14 rows selected.
Smith
*
Allan
*
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Ward
*
Jones
*
Martin
*
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Blake
*
Clark
*
King
*
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Turner
*
Adams
*
Miller
*
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
James
*
Ford
*
14 rows selected.
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Scott
*****************************
Smith
**********
Allan
********************
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Ward
*************
Jones
***********************
Martin
*************
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Blake
*****************************
Clark
*****************************
King
******************************
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Turner
***************
Adams
************
Miller
*************
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
James
**********
Ford
**************************
14 rows selected.
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Scott
****************************
Smith
**********
Allan
********************
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Ward
*************
Jones
***********************
Martin
************
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Blake
****************************
Clark
*****************************
King
*****************************
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
Turner
**************
Adams
***********
Miller
*************
ENAME
--------------------
SALARY_REPRESENTATION
--------------------------------------------------------------------------------
James
*********
Ford
**************************
14 rows selected.
JOB_TYPE COUNT(*)
-------------------- ----------
Analyst 2
Clerk 4
Manager 3
President 1
Sales_man 4
30.Query to display the no. Of managers without listing their names.
COUNT(DISTINCTMANAGER)
----------------------
7
32.Query to display Name and Hire Date for all employees in the same
dept. As Blake.
ENAME HIRE_DATE
-------------------- ---------
Allan 20-FEB-81
Ward 22-FEB-81
Martin 22-APR-81
Blake 01-MAY-81
Turner 08-SEP-81
James 03-DEC-81
6 rows selected.
33.Query to display the Employee No. And Name for all employees who
earn more than the average salary.
ENO ENAME
--- --------------------
788 Scott
749 Allan
756 Jones
769 Blake
778 Clark
783 King
792 Ford
7 rows selected.
34.Query to display Employee Number and Name for all employees who
work in a department with any employee whose name contains a ‘t’.
ENO ENAME
--- --------------------
793 Miller
35.Query to display the names and salaries of all employees who report
to King.
ENAME SALARY
-------------------- ----------
Jones 2300
Blake 2870
Clark 2900
36.Query to display the department no, name and job for all employees
in the Sales department.
6 rows selected.