Transcript

SQL Assignment 1

TABLES:-

1

1) List all the information about all employees from emp_mca table

2) List all employee names along with their salaries from emp_mca.

3) List the employees belonging to the department 20

2

4) List the names of asst.prof. working in the department no 10

5) List the names of teaching and manegment.

6) List the names of employees who are not supervisors.

7) List the names of the employees whose employee number are 4572,5821,2544.

3

8) List the employee name and salary, whose salary is between 30000 and 60000.

9) List the different jobs available in the emp_mca table.

10) List the employees whose names start with ‘R’.

11) List the employee names having ‘A’ as the second character.

4

12) List out the employees whose name start with “R” and end with “H”

13) List out the employees whose name length is 5 and start with “R”

14) List out the employees who are working in department 10 and draw the salaries more than 20000

15) List the name, salary and PF amount of all the employees (PF is calculated as 10% of salary).

5

16) List the empno, ename, sal in ascending order of salary.

17) List the employee name, salary, job and deprtment no in ascending order of department no and then descending order of salary.

18) List the number of employees working with the company.

19) List the number of jobs available in the emp_mca table.

6

20) List the total salaries payable to employees.

21) List the maximum salary of employee working as a Prof.

22) List the average salary and number of employees working in the department 20.

***************

7

Assignment No. 2

TABLE:--

1. List the employee numbers, names, department numbers and the department name.

2. Display the list of employees working in each department. Display the department information even if no employee belongs to that department.

8

3. List the employee names along with their manager’s name.

4. List all employees who joined the company before their managers.

5. Display the different designations in department no 20 and 30.

9

6. List the jobs common to department 20 and 30.

7. List the jobs unique to department 20.

8. List the employees belonging to the department of MILLER.

9. List the job with highest average salary.

10. List the names of the employees, who earn lowest salary in each department.

10

11. List employee details who earn salary greater than the average salary for their department.

12. List employee details whose salary is greater than average salary of all the employees joined before 1st April 1981.

**********************

11

SQL Assignment 3

1. give the  departments wise listing of employees in the organization

2. List out the department wise maximum salary, minimum salary, average salary of the employees\

3. List out the job wise maximum salary, minimum salary, average salaries of the employees.

4. List out the no.of employees joined in every month in ascending order.

12

5. List out the no.of employees for each month and year, in the ascending order based on the year, month.

6. List out the department id having atleast three employees.

7. How many employees in January month.

13

8. How many employees joined in January or September month.

9. How many employees joined in 2010.

10. How many employees joined each month in 2008.

11. How many employees joined in March 2008.

12. Update the employee’s salaries, who are working as Clerk on the basis of 10%.

14

13. Delete the employees who are working in marketting department.

14. Display the second highest salary drawing employee details.

15. List out the employees who earn more than every employee in department 30.

16. List out the employees who earn more than the lowest salary in department 30.

15

17. List out the employees who earn more than their managers

18. Find out which department does not have any employees.

19. Find out the employees who earn greater than the average salary for their department.

20. List our employees with their department names

16

21. Display the number of employees working in different departments along with department name.

22. How many employees who are working in teaching department.

23. Which is the department having greater than or equal to 3 employees and display the department names in ascending order.

24. How many employees working in “NEW DELHI”.

25. Display the employee details with their manager names.

17

26. Show the no. of employees working under every manager.

27. Display employee details with all departments.

18

28. Display all employees in sales or operation departments

19

29. List out the distinct jobs in Sales and Accounting Departments.

30. List out the common jobs in Research and Accounting Departments in ascending order.

20

University Practical ListQ1. Modify the structure of the employee_master table to have primary key constraint on the filed employee_no.

Q2. Modify the structure of order_master table to have foreign key constraint on the field employee_no.

Q3. Write a query to select the vendor id, name and phone o. of vendor who lives in the state of u.p.

21

Q4. Write a query to select the name and address of vendor whose name contain the letter ‘a’.

Q5. Write a query to count the no. of vendors who fall in the state of “uttar pradesh” If the no. of vendors in the state of uttar pradesh are 3, the result should be as :

RESULT

-------------

No. of vendors in the state of uttar pradesh is 3

Q6. Write a query to select the vendor id, name and state of the vendor whose assress2 field has a ‘.’ Contained in it.

22

Q7. Write a query to list the details of vendors who does not belong to the state of “uttar Pradesh” and “rajasthan”

23

Q8. Write a query to list the material id, its description and stock available for those whose unit price falls above 600 but less than 900.

Q9. Write a query to display the information of a material whose unit price is either 450.25 or 600 or 700 or 900.

Q10. Write a query to display the information about the material value in the stock is less than equal to 5.

Q11. Write a query to change the address1 of vendor to “186,circular no. 2” whose vendor id is v1001.

24

Q12. Modify the date of birth to 23-aug-67 where employee id is e101.

Q13. Write a query to inform you about the vendor(s) in the following form :- (e.g.)

INFORMATION

----------------------

Vendor with id as v1001 lives in the state of uttar Pradesh.

25

Q14. Write a query to display the names of all employees whose commission is more than 10% of their basic salary and falls in the category of salesman.

Q15 . Write a query to select the employee no. and name of those employees who earn salary more than the average salary of all the employees working in the organization.

Q17 . Write a query to select the name, department name and location of employee who are designated as manager.

Q18. Write a query to display the name, designation, department name and location who does not work in the Kanpur office.

26

Q19. Write a query to list the name and id of all employees in alphabetical order of their name.

Q20 .Write a query to select the name and date of birth of those employees who are born before February 7, 1976.

27

Q21. Write a query to select the name and department of those employees who have age between 30 and 40 years.

Q22. Write a query to list the id, name and department no. of employees who are born in the month of october

28

SQL Stored Procedures

Creation of Table:

Records of Table:

Q1. Write a PL/SQL code that accept the account number from the user and check the users balance is less than minimum balance , only then deduct Rs. 200/- from the balance . The process is fired on the Acct_Mstr table.

SQL Procedure:

DECLARE

mCur_Bal number(11,2);

mAcct_No varchar2(7);

mFine number(4):=200;

mMin_Bal constant number(7,2):=5000.00;

BEGIN

mAcct_No:=&mAcct_No;

select curbal into mCur_Bal from acct_mstr where acct_no=mAcct_No;

29

IF mCur_Bal < mMin_Bal Then

Update acct_mstr set curbal=curbal-mFine

where acct_no=mAcct_No;

END IF;

END;

Q2. Create a simple loop such that a message is displayed when a loop exceeds a particular value.

DECLARE

i number:=0;

begin

loop

i:=i+2;

exit when i > 10;

end loop;

30

dbms_output.put_line('Loop exited, and value of I is : '|| to_char(i));

end;

Q3. Write a PL/SQL code to calculate the area of a circle for a value of radius varying from 3 to 7. Store the radius and the corresponding values of calculated area in an Use of Error Handling Use of Cursors :empty table named Areas , consisting of two columns Radius and Area

Creation of Table:

Records of Table :

31

Stored Procedure:

DECLARE

pi constant number(4,2) := 3.14;

radius number(5);

area number(14,2);

begin

radius:=3;

while radius<=7

loop

area:= pi * power(radius,2);

insert into area values (radius, area);

radius := radius+1;

end loop;

end;

32

Q4. Write a PL/SQL code that first withdraws an amount of Rs. 1500/-. Then deposits an amount of Rs. 50,000.Update the current balance . Then check to see that the current balance of all the accounts in the bank does not exceed Rs. 60,000. If the balance exceeds Rs 60,000 then undo the deposit just made.

Creation of Table:

Records of table:

Stored procedure :

DECLARE

mBal number(8,2);

begin

insert into trans_mstr(trans_no, acct_no, dt, type, particular, dr_cr, amt, balance)

values ('t100', 'ca10', '04-jul-2004', 'c', 'Telephone Bill', 'W', 1000, 31000);

update acct_mstr set curbal = curbal - 1500 where acct_no='ca10';

savepoint no_update;

insert into trans_mstr(trans_no, acct_no, dt, type, particular, dr_cr, amt, balance)

33

values ('t101', 'ca10', '04-jul-2004', 'c', 'Deposit', 'D', 50000, 171000);

update acct_mstr set curbal = curbal + 50000 where acct_no='ca10';

select sum(curbal) into mBal from acct_mstr;

if mBal > 60000 then

rollback to savepoint no_update;

end if;

commit;

end;

Q5 . Write a PL/SQL code that will reverse a given number like 12345 to 54321

Stored Procedure:

declare

given_number varchar(6) := '12345';

str_length number(3);

34

inverted_number varchar(5);

begin

str_length := length(given_number);

for cntr in reverse 1..str_length

loop

inverted_number := inverted_number || substr(given_number, cntr, 1);

end loop;

dbms_output.put_line('The given number is : ' || given_number);

dbms_output.put_line('The inverted number is : ' || inverted_number);

end;

35

Views

36

SEQUENCE

1. create sequence my_seq increment by 2 start with 10 minvalue 10 maxvalue 50 cycle cache 10;

2. select seq .nextval from dual;

INDEX :

37

top related