You are on page 1of 6

UPTEC Distance Education Division IGNOU

Computer Consultancy Ltd. Suggested Lab Assignment 508634


51.doc
NOTE: Learners should have programs written in their notebooks before
coming for the lab sessions.

1. Create the following tables: -

EMP: -
MPNO varchar2(4) Primary Key,
ENAME varchar2(20),
JOB varchar2(20),
MGR varchar2(4),
HIREDATE date,
SAL Number,
COMM Number,
DEPTNO varchar2(2)
DEPT: -
DEPTNO varchar2(2),
DNAME varchar2(20),
LOC varchar2(20),
SALGRADE: -
GRADE varchar2(2),
LOSAL Number,
LOC Number
NOW:-

a) Insert the following Data in EMP table using appropriate command.

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 10

b) Insert the following Data in DEPT table using appropriate command.

DEPTNO DNAME LOC

50863451.doc Programme Study Centre: Page 1 of 6


 2732(P) - UPTEC Lucknow - 16, Rana Pratap Marg, UPTEC Crossing, Lucknow.
 2787(P) - UPTEC Varanasi - Shiva Complex, 1st Floor, Rath Yatra Crossing, Varanasi.
 2792(P) - UPTEC NOIDA – A-358, Atta Peer Crossing, Sector – 19, NOIDA.
UPTEC Distance Education Division IGNOU
Computer Consultancy Ltd. Suggested Lab Assignment 508634
51.doc
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

c) Insert the following Data in SALGRADE table using


appropriate command.
GRADE LOSAL HISAL
1 700 1200
2 1201 1400
3 1401 2000
4 2001 3000
5 3001 9999

Based upon above tables solve the queries given below


Q1. Alter table DEPT and make deptno a Primary Key.
Q2. Make deptno a foreign key in the EMP table referring deptno of
DEPT table.
Q3. Create a query to display the name, job, hiredate and employee
number for each employee with employee number appearing first.
Q4. Create a query to display the name and salary of employees earning
more than Rs. 2850.
Q5. Display the name and salary of employees whose salary is not in
the range of Rs.1500 and Rs.2850.
Q6. List the name and salary of employees who earn more than Rs.
1500 and are in department 10 or 30. Label the columns Employee
and Monthly Salary.
Q7. Display name, salary and commission for all employees who earn
commissions. Sort the data in descending order of salary and
commissions.
Q8. Display name, salary and job for all employees whose job is Clerk
or Analyst and salary is not equal to Rs.1000, Rs.3000, Rs.5000.
Q9. List the Total salary payable to employees in the company.
Q10. List the Maximum, Minimum, Average salary of employees working
in department number 20.
Q11. List the name and Annual salary of each employee.

50863451.doc Programme Study Centre: Page 2 of 6


 2732(P) - UPTEC Lucknow - 16, Rana Pratap Marg, UPTEC Crossing, Lucknow.
 2787(P) - UPTEC Varanasi - Shiva Complex, 1st Floor, Rath Yatra Crossing, Varanasi.
 2792(P) - UPTEC NOIDA – A-358, Atta Peer Crossing, Sector – 19, NOIDA.
UPTEC Distance Education Division IGNOU
Computer Consultancy Ltd. Suggested Lab Assignment 508634
51.doc
Q12. Display Sum of salaries in the EMP table for each job.
Q13. Display Number of Employees in each department.
Q14. Display total number of managers without listing them. Label the
column ‘No OF Managers’.
Q15. Write a query that will display the difference between highest and
lowest salaries. Label the column ‘DIFFERENCE’.
Q16. Write a query to display name and salary of all employees. Format
the salary to be 15 digits long, left padded with $. Label the column
as ‘Salary’.
Q17. Display the employee name and calculate the number of months
between today and the date the employee was hired. Label the
column ‘Months-Worked’ and order the result by the number of
months employed. Round the number of months to the nearest
whole number.
Q18. Display the employee name and department name for all employees
who have an ‘A’ in their name.
Q19. Display the Employee Name and empno along with manager’s name
and number. Label the columns Employee, Emp#, Manager and
Mgr# respectively.
Q20. Display the total number of employees and of that total the number
who were hired in 1980, 1981, 1982 and 1983. The output should
be:-
Total 1980 1981 1982 1983
14 1 10 2 1
Q21. Write query to display the job, salary for that job based on
department number and the total salary for all departments, giving
each column an appropriate heading i.e.;
JOB Dept10 Dept20 Dept30 Total
Analyst 6000 6000
Clerk 1300 1900 950 4150

Q22. Write SQL statement to display all the departments that have a
minimum salary greater than that of department 20.
Q23. Find the Job with lowest average salary.
Q24. Find the Employees who earn the same salary as the minimum
salary for the department.

50863451.doc Programme Study Centre: Page 3 of 6


 2732(P) - UPTEC Lucknow - 16, Rana Pratap Marg, UPTEC Crossing, Lucknow.
 2787(P) - UPTEC Varanasi - Shiva Complex, 1st Floor, Rath Yatra Crossing, Varanasi.
 2792(P) - UPTEC NOIDA – A-358, Atta Peer Crossing, Sector – 19, NOIDA.
UPTEC Distance Education Division IGNOU
Computer Consultancy Ltd. Suggested Lab Assignment 508634
51.doc
Q25. Write a query to display the employee number and name for all
employees who earn more than the average salary. Sort the results
in ascending order of salary.
Q26. Display department number, Employee name and job for all
employees in sales department.
Q27. Display the list of employees who earn a salary that is higher than
the salary of all the clerks. Sort the results on salary from highest
to lowest.

2. Make Tables and insert data as follows: -


SHOP
SHOP_NO SHOP_NAME ADDRESS OWNER
1 UNIVERSAL LUCKNOW SMITH
2 COMPU SHOPPE LUCKNOW ALLEN
3 BOOKS & BOOKS KANPUR JONES
4 RAMA KANPUR MARY

CUSTOMER
C_NO C_NAME C_ADDRESS
101 ASHOK LUCKNOW
102 ASHA LUCKNOW
103 ROOPA KANPUR
104 SMITA KANPUR

ITEM
I_NO I_NAME
A1 BOOK
A2 PENCIL
A3 FILE

REQUIRES
C_NO I_NO
101 A1
102 A1
103 A2
102 A2
104 A3
103 A1
102 A3
101 A3
104 A2

50863451.doc Programme Study Centre: Page 4 of 6


 2732(P) - UPTEC Lucknow - 16, Rana Pratap Marg, UPTEC Crossing, Lucknow.
 2787(P) - UPTEC Varanasi - Shiva Complex, 1st Floor, Rath Yatra Crossing, Varanasi.
 2792(P) - UPTEC NOIDA – A-358, Atta Peer Crossing, Sector – 19, NOIDA.
UPTEC Distance Education Division IGNOU
Computer Consultancy Ltd. Suggested Lab Assignment 508634
51.doc
SUPPLIED
I_NO C_NO SHOP_NO DATE PRICE
A1 101 1 03-JAN-97 1000
A1 102 1 07-JAN-97 500
A2 103 2 10-JAN-90 200
A3 104 2 01-MAR-97 500
A2 102 1 02-APR-92 950
A3 101 3 03-JUN-95 800
A3 102 1 10-APR-00 2000

Based On Above Tables Solve The Following: -


Q1. Find the name of customers who have been supplied items of maximum
total value.
Q2. Find the name of customers who require items but have not been supplied
(along with item names).
Q3. Find names of customers who were supplied all the items from only one
shop.
Q4. List the shop owners who supplied some item in the address ‘Kanpur’.
Q5. Find names of shop owners along with shop numbers whose rate were the
maximum.
Q6. Find the name of customers who are supplied with some items.
Q7. Find the name of all the customers who are supplied with Book.
Q8. Find the name of customers who were supplied with all items they
require.
Q9. Find the item no, item name, customer no and customer name of
customers whose price for items supplied was greater than 500.

TRIGGERS, PROCEDURES AND FUNCTIONS


Q1. Write a Procedure, which calculates and prints PF for Employee No 7369.
The PF will be 12% of salary.
Q2. Write a Function, which calculates and prints PF for Employee No, which
is passed as an argument. The PF will be 12% of salary.
Q3. Write a procedure to calculate Total Purchase Cost In Rupees of the Book
Shop named ‘Universal’ for the month of January 1997.
Q4. Write a function to calculate Annual income of a given Employee.
Emp_Name is passed as an argument.

50863451.doc Programme Study Centre: Page 5 of 6


 2732(P) - UPTEC Lucknow - 16, Rana Pratap Marg, UPTEC Crossing, Lucknow.
 2787(P) - UPTEC Varanasi - Shiva Complex, 1st Floor, Rath Yatra Crossing, Varanasi.
 2792(P) - UPTEC NOIDA – A-358, Atta Peer Crossing, Sector – 19, NOIDA.
UPTEC Distance Education Division IGNOU
Computer Consultancy Ltd. Suggested Lab Assignment 508634
51.doc
Q5. Write a procedure to calculate and print number of employees in each
Department using Cursor.
Q6. Write a procedure to calculate and print yearly income of every employee
of DeptNo 10 using Cursor.
Q7. Write a procedure to calculate and print number of employees falling in
any particular Grade for each Department.
Q8. Write a procedure to print all the customers, who belong to Lucknow with
the total amount they spent in purchasing books.
Q9. Write a procedure to print Customer names with the items they require as
well as shop, which can provide that item. This procedure should call a
function, which took 2 parameters Item_no and Shop name and returns ‘1’
if that item can be supplied by that shop otherwise ‘0’. The Output should
be like this: -

Customer Name Item Shop


101 A1 Universal
101 A3 Books And Books
102 A1 Universal
102 A2 Universal
102 A2 Books And Books
Q10. Write a Trigger on insert to Emp table which Updates Dept table by
increasing No_Of_Employees for that particular Dept_no to which new
inserted employee belongs.
Q11. Write a Trigger on Deleting record from Emp table which Updates Dept
table by decreasing No_Of_Employees for that particular Dept_no to
which last deleted employee belongs.
Q12. Write a Trigger on Updating record of Emp table on transfer case of any
employee by Updating Dept table by decreasing No_Of_Employees for
that particular Dept_no from which employee transferred and by
increasing No_Of_Employees to which employee transferred.

50863451.doc Programme Study Centre: Page 6 of 6


 2732(P) - UPTEC Lucknow - 16, Rana Pratap Marg, UPTEC Crossing, Lucknow.
 2787(P) - UPTEC Varanasi - Shiva Complex, 1st Floor, Rath Yatra Crossing, Varanasi.
 2792(P) - UPTEC NOIDA – A-358, Atta Peer Crossing, Sector – 19, NOIDA.

You might also like