SQL Lab

1. Create the table PROGRAMMER with the given information using SQL CREATE TABLE commands:
Attribute Name EmpNo ProjId LastName FirstName HireDate Language TaskNo Privelege Description/Data type/Constraint Employee’s Unique ID. Max 5 characters should be numeric Project in which programmer participates. Max 3 characters should be numeric Surname of employee. Max 30 characters Required. Employee’s first name. Max 30 characters Date on which employee was hired. Date data type Programming Language used by programmer. Max 15 characters Number of the rask associated with the project. Numeric column, max 2 digits Type of privilege given to programmer. Max 25 characters

2. Insert the following data into the PROGRAMMER table
EmpNo 201 390 789 134 896 345 563 LastName Gupta Ghosh Agarwal Chaudhury Jha John Anderson FirstName Saurav Pinky Praveen Supriyo Ranjit Peter Andy Hiredate 1/1/95 1/5/93 8/3/98 7/15/95 6/15/97 11/15/99 08/15/94 ProjId NPR KCW RNC TIPPS KCW TIPPS NITTS Language VB JAVA VB C++ JAVA JAVA C++ TaskNo 52 11 11 52 10 52 89 Privelege Secret TopSecret Secret Secret TopSecret Confidential

3.

Write SQL queries to: a. Saurav Gupta is assigned a different project with id NITTS and he would work with C++ now. Update this change in the PROGRAMMER table. b. Supriyo Chaudhury has resigned his job. Incoprate this in the table PROGRAMMER. c. The column TaskNo in the PROGRAMMER table is no longer needed. Delete the column.

Name of the employee. CLERK. Insert the following DATA into the Employee Table . Create table Department Attribute Name DeptNo Dname Loc Description/Data type/Constraint Department number is Unique ID. Create table Employee Attribute Name EmpNo Ename Job Sal Hiredate Deptno Description/Data type/Constraint Employee number is Primary Key. increase the field width if DNAME from 20 to Insert the following data into the Department table DEPTNO 10 20 30 40 DNAME ACCOUNTS MARKETING SALES RESEARCH LOC NEWYORK CHICAGO ATLANTA OHIO 7. 50 6.4. In EMPLOYEE table add a new attribute MGR(Manager ID) consisting 4 Characters 9. Department name of a particular department. PRESIDENT Cannot be null Cannot be null Should reference Department Table. Location of the department. The job of the employee can be MANAGER. 5. loc should not be null. In DEPARTMENT table. Deptno 8. Dname should not be null. Cannot be null Cannot be null.

Create table Grade Attribute Name GradeNo Hi_sal Lo_sal Description/Data type/Constraint Grade number is Primary Key. 13. 15.EMPNO 7001 7002 7003 7004 7005 ENAME JAMES MASON CLARK JOHN BLAKE JOB CLERK PRESIDENT MANAGER MANAGER CLERK SAL 3000 10000 5000 6000 3500 HIREDATE DEPTNO 6/5/2005 10 6/6/2005 20 6/5/2004 20 6/8/2005 10 6/9/2005 30 10. 18. 12. 17. Drop the column Lo_sal from Grade Table Add column Low_sal in Grade table Insert the following data into the table GRADE_NO 1 2 3 4 HI_SAL 2000 3500 6000 15000 LO_SAL 500 2100 3600 6100 14. Cannot be null Cannot be null 11. 16. Create table EMPLOYEE_BACK from employee table Increase the salary of JAMES from 3000 to 3500 Increase the salary of all MANAGER by 1000 Decrease the salary of DEPTNO 10 by 100 Add a new field COMM in EMPLOYEE table Initialize the value of COMM to zero in EMPLOYEE table. . 19.

) Display the salary of employees of MANAGER increased by 10%. 40. List the employees who are not a PRESIDENT or MANAGER List all employees whose name begin with J List all employees whose name consists of A List the employee sal. List all employees who are in deptno 10 or 20 and who are MANAGERS Update the commission of employees in deptno 10 to 500. . 25. 21. 30. 37. and bonus (Bonus is sal+comm. 33. 26. 41. The output should display salary and increased salary. 24. 42. 29.20. 23. 36. 31. Display the employees in the desscending order of names Display the employees in the ascending order of deptno. Remove the employees who have joined before 6-Jun-2005 Remove employees whose salary is less than 3000 List all employees who are working in department 10. List all employees whose commission is null. Job Display all the employee names with the first letter in capitals and all the other characters in lower case Display all the employee names in lower case Display the employee name and the position of letter A in each name Extract the last 3 characters in employee name and display them. comm. Update the salary of MANAGER by 10%. 28. List all employees of department 10 and are MANAGER List all employees whose salary is between 3000 and 5000 List all employees who have joined after 10th July 2005 List all employees who are MANAGER or PRESIDENT 27. 35. Display the employee name and the length of the name Display the current system date and time 39. 22. 43. 34. 32. 38.

Display the employee earning the lowest salary ans: select ename from employee where sal=(select min(sal) from employee). Display the average salary for each department .44. 49.count(job) from employee group by job. 53. Drop table employee EMPLOYEE_BACK Display the number of employees in department 10 Display the number of employees in each department ans deptno. : select deptno. 50. sal and comm. 51. Display the employee earning the highest commission ans: select ename from employee where comm=(select max(comm) from employee). for all employees. 45.count(deptno) from employee group by 52. Display the employee earning the highest salary ans: select ename from employee where sal=(select max(sal) from employee). 46. Employees having commission as null should be displayed as 99 47. hiredate and the total months of experience as on 8th June 2008 Display the employee name. Display the employee name and the date when each employee completes 5 years in the company Display the last day of the month for the current system date Display the last day of the month for all the hiredates in EMPLOYEE table Display the employee name. Display the number of employees in each department job wise ans : select job. Display the total number of employees in the table ans : select count(empno) from employee. 48. 57. 55. 56. 54.

List the employees who are in the same department as that of CLARK List the employees who drawing the same salary as that of BLAKE List the employees whose salary is greater than the average salary List the employees who are located in NEWYORK or CHICAGO 69. 62. Display the employee name. Create a table EMPLOYEE_DUP from EMPLOYEE. 59. ans:select count(deptno) from employee where deptno>3. Check for the balance salary and display the appropriate message. Display the total salary department wise ans:select sum(sal) from employee group by deptno. Increase the salary of employees by 10% . 65. If the deduction causes value to be less than zero display “Insufficient for Deduction”. List the employees whose salary is greater than the salary of BLAKE or CLARK. job and rank. 66. who are located in CHICAGO 70. Display the job and total salary for each job having number of employees greater than 5 63. Display distinct jobs in the table ans:select distinct(job) from employee. The new table should only have the structure and should not have any data values.avg(sal) from employee group by deptno. There is a deduction of 5000 from every employee’s salary. 58. Display the deptno where the number of employees is greater than 3. 60. 61. .ans:select deptno. if the job is CLERK then the rank is 3. 67. if greater than zero “Can be Deducted” 64. If the job is MANAGER then rank is 2 . If the job is PRESIDENT then rank is 1. 68.

72. 75.71. 77. name and location for the department for which there exists employees Create a view emp_vw consisting of ename. department name and location Create a sequence emp_seq Create a sequence emp_seq1 starting with 1 and increment it by 1 Implement the sequence while creating table. Delete the employees whose rowid is greater than the rowed of CLARK List the employees whose salary is greater than the average salary of his own department. sal. 73. sal . job. sal and job of employees located in CHICAGO Create a view emp_dept consisting of employee names. 78. 79. 74. job of employees in department 10 Create a view emp_vw1 consisting of employee names. List the employees who are not in the same department as that of BLAKE or CLARK Display the department number. 76. . 80.

Sign up to vote on this title
UsefulNot useful