Sei sulla pagina 1di 4

Hands-On SQL

Instructions:
1. Logon to the Personal MS-SQL Server.
2. Store all your SQL commands in the .SQL file on your system desktop.

PART-A

Create the following tables based on the structure given.

EMP TABLE

EMPNO NUMBER 8,2 NOT NULL


ENAME CHARACTER 20
JOB CHARACTER 15
MGR NUMBER 4
HIREDATE DATE
SALARY NUMBER 8, 2
COMM NUMBER 8, 2
DEPTNO NUMBER 3

BONUS TABLE

ENAME CHARACTER 20
JOB CHARACTER 15
SAL NUMBER 8, 2
COMM NUMBER 8, 2

SALGRADE TABLE

GRADE NUMBER NOT NULL


LOSAL NUMBER 8, 2
HISAL NUMBER 8, 2

DEPT TABLE

DEPTNO NUMBER NOT NULL


DNAME CHARACTER 15

PROJ TABLE

PROJNO NUMBER NOT NULL


PNAME CHARACTER 10
BUDGET NUMBER 8, 2
LOC CHARACTER 15

a. Add the following records as per the table to the all tables created so far but for the
BONUS table.
EMPLOYEE TABLE
EMPNO ENAME JOB MGR HIRE SALARY COMM DEPTNO
DATE*
1111 Manohar Arya PROJ-MGR 88000 99000 110
1112 Raashi Sharma DEVELOPER 1115 21760 0 120
1113 Shabana Parveen SR. 1121 26780 17600 130
DEVELOPER
1114 Indrani S TEST 1111 21970 110
1115 Sudhir Prasad PROJ-MGR 68000 22000 120
1116 Bhaskar Rao ARCHITECT 1115 56000 12000 120
1117 Srikanta M S TEST 1111 23450 0 110
1118 Satish Naik LEAD TEST 1111 31800 15000 110
1119 Meera Raghavan PROJ.LEAD 1115 47000 34000 120
1120 Vijaya C K SR. 1115 32800 23980 120
DEVELOPER
1121 Dipesh Mehta PROJ-MGR 78000 46890 130
1122 Arun Chawla TEST 1115 24500 0 120
1123 Piyush Patel PROJ.LEAD 1111 38000 22000 110
1124 G Rajashekhar LEAD TEST 1115 32000 19750 120
1125 Ganesh D ARCHITECT 1121 31000 130
1126 Amir Ali LEAD TEST 1121 34560 18770 130
1127 Naveen Paul TEST 1111 22450 0 110
1128 Sonali Mohanty DEVELOPER 1115 23450 0 120
1129 Mohd. Shariff SR. 1121 34560 17000 130
DEVELOPER
1130 Shubhangi Bose LEAD TEST 1111 29000 0 110
* Please enter the HIREDATE less than today’s date for all employees.

SALGRADE
GRADE HISAL LOSAL
A 100000 70001
B 70000 50001
C 50000 28001
D 28000 0

DEPT
DEPTNO DNAME
110 APPL-ENGG
120 REQUIREMENTS-DESIGN
130 TESTING-IMPL
140 GLOBAL-DELIVERY

PROJ
PROJNO PNAME BUDGET LOCATION
1 ABN-AMRO 80.5 MYSORE
2 CITIBANK 110.10 BANGALORE
3 HSBC 150.5 MYSORE
4 ANZ 72.5 BANGALORE
5 TELSTAR 100.00 CHENNAI
Copy rows from EMP table into the BONUS table.

PART-B

1. List all employee names, numbers and departments.


2. List the names and departments of all the employees who are managers.
3. List information about all the employees who work for MANOHAR
4. List the columns DNAME and DEPTNO from the table DEPT
5. List all the jobs in the table EMP
6. List all the unique jobs in the table EMPS
7. List information about employees in Department 130.
8. List the names, numbers and departments of all TEST.
9. Find all department names with department numbers greater than 120.
10. Find all employees whose commission exceeds their salary.
11. Find all employees in department 130 whose salary is greater than or equal to 25000.
12. Find all employees who are either managers or have a salary greater than 30000.
13. List information about employees in department 110 who are not managers or test.
14. Find employees who are earning between 22000 and 30000 inclusive of both.
15. List names and department numbers of employees who are test, architects or developers.
16. List jobs and departments of employees whose names begin with M or S.
17. List jobs and departments of employees whose names begin with SH and ending with N.
18. List grades for the salary falling in the range 30010 to 99999 and 70000 to 90000.
19. List employees and jobs in department 110 and 120 in order of their salary.
20. Set the salaries of all developers equal to 1:1 times the average salary of developers.
21. Assign Naveen Paul to TESTING-IMPL staff and give him 10% raise in salary.
22. Give 15% raise to all architects in department 120.
23. Delete the record of INDRANI S from the BONUS table.
24. Delete all employees with the same job as Bhaskar Rao from the BONUS table.
25. Change the BUDGET column to accept numbers with up to nine digits.
26. Add a new PROJNO column to EMP table with no constraints.
27. Assign the projects to the employees as below:

EMPNO PROJNO
1111 1
1112 2
1113 3
1114 1
1115 2
1116 2
1117 1
1118 1
1119 2
1120 2
1121 5
1122 2
1123 1
1124 2
1125 5
1126 4
1127 1
1128 2
1129 4
1130 5

28. Join EMP and DEPT and list departments 130 and 140 with or without employees.
29. Display information about employees earning more than any employee in Dept. 130.
30. List employees in Dept. ‘APPL-ENGG’ with the same job as anyone in dept. 130.
31. List employees with either the same job as SHUBHANGI, or as salary greater than or equal to
VIJAYA C K’s in order by job and salary.
32. List employees in dept.110 with the same job as anyone in the TESTING dept.
33. Find all the average salary of employees in their own departments, and list them, in department
order.
34. Display information about employees who have at least one other employee reporting to them.
35. List the name and job of the employees earning the highest salary.
36. List each EMPLOYEE and the PROJECT and LOCATION where they work.
37. Calculate the total compensation for all TEST people.
38. List employees whose commission is greater than 15% of their salary.
39. List developers in descending order of their commission divide by their salary.
40. Calculate total annual compensation of employees who are not managers.
41. Display name, and the greater value of salary or commission.
42. Find the average and total salaries of all PROJECT MANAGERS.
43. Find the highest and lowest salaries and the difference between them.
44. Find the average annual compensation of all appl-engg people.
45. Count the employees who are in TESTING as architects.
46. Count the number of different jobs held by employees in department 130.
47. Count the number of employees not belonging to department 130.
48. List average salary of each department.
49. Find the average maximum salary of the non managerial staff.
50. Display information about all employees who are not eligible to receive commissions.
51. Compute SAL + COMM treating null commissions as zero.
52. Compute years of service for each employee in department 110.
53. List the name and year of hire for each salesperson.
54. Sort the details of employees by job and in the descending sequence of salary.
55. List the locations where the budget for the projects exceeds 75 million.
56. List the employees who are working for the TELSTAR project.
57. List the employees who are in more than one project.
58. List the names of employees who work in locations in the Chennai region.
59. Create a view of EMP that excludes the fields SAL and COMM
60. Create a view joining EMP to PROJ
61. Define a view named PAY which calculates annual salary.
62. Create a view showing testing department employees.
63. Define a view of the employee table that includes only project names and their assignment to
employee.
64. Create an index on column ENAME of table EMP
65. Create a unique index on EMPNO.
66. Find all the employees who earn more than the average salary of employees in their own
departments, and list them, in department order.

Potrebbero piacerti anche