0% found this document useful (0 votes)
11 views

248154_Onkar Khade Database Technologies Lab Assignments

Uploaded by

daratmpxur1s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

248154_Onkar Khade Database Technologies Lab Assignments

Uploaded by

daratmpxur1s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 185

Name : Onkar Khade

Rollno : 248154
Practical Batch : B

Database Technologies Lab Assignments :


Database Assignment
1 Note : Use Emp, dept and salgrade table
1. To list all records with sal > 2000 and comm>200
Code and Output :

2. To list all record with job=’Clerk’ or sal>2000


Code and Output :
3. To list all the record with sal=1250 or 1100 or 2850
Code and Output :

4. To list all employees with sal>1250 and <2850


Code and Output :

5. To list all employees with name ends with AS


Code and Output :
6. To list all employees with job starts with C and ends with K
Code and Ouput :

7. To list all employees with job contains L at third


position and M at third last position
Code and Output :

8.To list all the record with sal not equal to 1250 or 1100 or 2850
Code and Output :
9. To list all employees with sal not >1250 and <2850
Code and Output :

10. To list all employees with job starts with C , E at 3rd position and ends with
K
Code and Output :

11. To list all rows with comm is null


Code and Output :
12. To list all employees with sal is null and name starts with ‘S’
Code and Output :

13. To list all employees with job contains 5 characters


Code and Output :

14. To list all employees with name contain ‘A’ at 1 position and job Contains 5
characters
Code and Output :
Q2. Solve the following
1. Retrieve the details (Name, Salary and dept no) of the emp who are working
in department code 20, 30 and 40.
Code and Output :

2. Display the total salary of all employees . Total salary will be calculated as
sal+comm+sal*0.10
Code and Output :
3. List the Name and job of the emp who have joined before 1 jan 1986 and
whose salary range is between 1200and 2500. Display the columns with user
defined Column headers.
Code and Output :

4. List the empno, name, and department number of the emp works under
manager with id 7698
Code and Output :

5. List the name, job, and salary of the emp who are working in
departments 10 and 30.
Code and Output :
6. List the name, job, and salary of the emp who are working in departments
10 and Display name concatenated with dept code separated by comma and
space. Name the column as ‘Emp info’.
Code and Output :

7. Display the emp details who do not have manager.


Code and Output :

8. Write a query which will display name, department no and date of joining of
all employee who were joined January 1, 1981 and March 31, 1983. Sort it
based on date of joining (ascending).
Code and Output :
9. Display the employee details where the job contains word ‘AGE’ anywhere in
the Job
Code and Output :

10. List the details of the employee , whose names start with ‘A’ and end with
‘S’ or whose names contains N as the second or third character, and ending
with either ‘N’ or ‘S’.
Code and Output :

11. List the names of the emp having ‘_’ character in their name.
Code and Output :
Group functions
1. Display the Highest, Lowest, Total & Average salary of all employee. Label the
columns Maximum, Minimum, Total and Average respectively for each
Department. Also round the result to the nearest whole number.
Code and Output :

2. Display Department no and number of managers working in that


department. Label the column as ‘Total Number of Managers’ for each
department.
Code and Output :

3 Get the Department number, and sum of Salary of all non managers where
the sum is greater than 20000.
Code and Output :
Day 2 Assignment
Write SQL statement for the following
1. To find all managers with salary >1500
Code and Output:

2. list all employees with sal >1200 and < 2000


Code and Output:
3. list all employees with sal is 1600 or sal is 800 or sal is 1900
Code and Output:

4. list all employees with R at second last position in name


Code and Output:

5. List all employees with name starts with A and ends with N
Code and Output:

Q2. Solve following


1. list all employees with salary > 1250 and dept no=30
Code and Output :
2. list all employees with salary >=1250 and <= 3000
Code and Output :

3. list all employees with salary >1250 and < 3000


Code and Output :

4. list all employees with salary either equal to 3000 or 1250 or 2500
Code and Output :
5. list all employee with name=SMITH
Code and Output :

6. list all employees with name starting with S


Code and Output :

7. list all employees with name ending with S


Code and Output :
8. list all employees with name contains I at 2nd position
Code and Output :

9. list all employees with name starts with A ends with N and somewhere in
between L is there
Code and Output :

10. list all employees with name starts with A and B at 3 rd position and P at
second last position
Code and Output :
11. List all employees with name starts with either A or starts with S or
starts with W
Code and Output :

practice Aggregate functions

12. find max sal and min sal for each job
Code and Output :

13. find how many employess have not received commission


Code and Output :
14. find sum of sal of all employees working in dept no 10
Code and Output :

15. find maximum salary,average sal for each job in every department
Code and Output :

16. find max salary for every department if deptno is > 15 and arrange data
in deptno order.
Code and Output :
17. find sum salary for every department if sum is > 3000
Code and Output :

18. list all department which has minimum 5 employees


Code and Output :

19. count how many employees earn salary more than 2000 in each job
Code and Output :

20. list all enames and jobs in small case letter


Code and Output :
21. list all names and jobs so that the length of name should be 15 if it is
smaller then add spaces to left
Code and Output :

22. display min sal,max sal, average sal for all employees working under
same manager
Code and Output :
23. find sum of total earnings(sal+comm), average of sal+comm for all
employees who earn sal > 2000 and work in either dept no 10 or 20
Code and Output :

24. list all employees who joined in Aug 1980 and salary is >1500 and <
2500
Code and Output :

25. list all employees joined in either aug or may or dec


Code and Output :
26. display name and hiredate in dd/mm/yy format for all employees
whose job is clerk and they earn some commission
Code and Output :

27. list empcode,empno,name and job for each employee. (note :empcode
is 3 to 5 characters from name and last 2 characters of job)
Code and Output :

28. display thousand separator and $ symbol for commission if it is null


then display it as 0 for all employees whose name starts with A and ends
with N
Code and Output :
29. Display empid,name,sal,comm,remark Remark should base on following
conditions comm >= 600 "excellent Keep it up" if it < 600 or not null "good"
otherwise "Need improvement"
Code and Output :

30. Display empid, name, deptno and department name by using following
conditions. dept 10 then "Hr" if 20 then "Admin" if 30 then "accounts"
otherwise purchase
Code and Output :
Topic ----------------- create Table, DML , subquery and joins
31. Practice creating following tables
create table mydept_DBDA ( deptid number primary key, dname
varchar2(20) not null unique, dloc varchar2(20) )
insert into mydept_DBDA values(30,'Purchase','Mumbai');
Code and Output :
create table myemployee ( empno number(5) primary key, fname
varchar2(15) not null, mname varchar2(15), lname varchar2(15) not null, sal
number(9,2) check(sal >=1000), doj date default sysdate, passportnum
varchar2(15) unique, deptno number constraint fk_deptno references
mydept_DBDA(deptid) on delete cascade )
Code and Output :

32. Create following tables Student, Course Student


(sid,sname) ---------------- sid ---primary key
Code and Output :
Course(cid,cname)-------------- cid ---primary key
Code and Output :

Marks(studid,courseid,marks) Sample data for marks table


studid,courseid,marks
1 1 99
1 3 98
2 1 95
2 2 97
create table marks( studid number, courseid number, marks number,
constraint pk primary key(studid,courseid), constraint fk_sid foreign key
(studid) references student(sid) on delete cascade, constraint fk_cid foreign
key (courseid) references course(cid) )
Code and Output :
33. Create empty table emp10 with table structure same as emp table.
create table emp10 as
(
select * from emp where 1=2;
)
Code and Output :
34. Solve following using alter table add primary key constraint on
emp,dept,salgrade
emp ----→ empno

dept---→ deptno

salgrade---→ grade

add foreign key constarint in emp deptno --->> dept(deptno)

add new column in emp table netsal with constraint default 1000
35. Update employee sal ---- increase sal of each employee by 15 % sal +comm,
change the job to manager and mgr to 7777 for all employees in deptno 10.
36. change job of smith to senior clerk
37. increase salary of all employees by 15% if they are earning some
commission

38. list all employees with sal>smith's sal


39. list all employees who are working in smith's department

40. list all employees with sal < rajan's sal and salary > revati's sal

41. delete all employees working in alan's department


42. change salary of Alan to the salary of Miller.

43. change salary of all emplees who working in Wall's department to the
salary of Miller.

44. list all employees with salary > either Smith's salary or alan's sal
45. list all employees who earn more than average sal of dept 10

46. list all employees who earn more than average sal of Alan's department

47. list all employees who are working in purchase accounts

48. list all employees who earn more than average salary of their own
department
49. list all employees who earn sal < than their managers salary

50. list all employees who are earning more than average salary of their job

51. display employee name and department


52. display empno,name,department name and grade (use emp,dept and
salgrade table)

53. list all employees number,name, mgrno and manager name


54. create following tables and solve following questions(primary keys are
marked in yellow) foreign keys are marked in green
product(pid,pname,price,qty,cid,sid) salesman (sid,sname,address)
category(cid,cnam,descritpion)
1. list all product name,their category name and name of a person, who sold
that product

2. list all product name and salesman name for all salesman who stays in pune

3. list all product name and category name

55. create following tables and solve following questions(primary keys are
marked in yellow) foreign keys are marked in green
faculty(fid,fname,sp.skill1,sp.skill2) courses(cid,cname,rid,fid)
room(roomid,rname,rloc)
Room
roomid rname rloc
100 jasmin 1st floor
101 Rose 2nd floor
105 Lotus 1st floor
103 Mogra 1st floor
1. list all courses for which no room is assigned and all rooms for which are
available
2. list all faculties who are not allocated to any course and rooms which are not
allocated to any course

3. list all rooms which are allocated or not allocated to any courses

4. list all rooms which are not allocated to any courses

5. display courses and faculty assigned to those courses whose special skill is
database
6. display time table --- it should contain course details , faculty and room
details

56. create following tables with given constraints product---- qty >0, default
20.00,pname not null and unique
1. List all products with category chips

2. display all products sold by kirti

3. display all salesman who do not sold any product


4. display all category for which no product is there

5. display all products with no category assigned

6. list all salesman who stays in city with name starts with P or N

7. add new column in salesman table by name credit limit


Assignment 3

1. create all given tables

2. create index on vehicle table based on price


3. find all customer name,vehicle name, salesman name, discount earn by all
customer

4. find all customer name,vehicle name,salesman name for all salesman who
stays in pune

5. find how many customers bought motor bike


6. create a view find_discount which displays output -------to create view create
view find_discount as select cname,vname,price,buying_price,price-
buying_price “discount” from customer c inner join cust_vehicle cv on
c.custid=cv.cid inner join vehicle v on v.vid=cv.vid --------to display discount
select * from find_discount

7. find all customer name, vehicle name, salesman name, discount earn by all
customer

8. create view my_hr to display empno,ename,job,comm for all employees who


earn commission
9. create view mgr30 to display all employees from department 30

10. insert 3 employees in view mgr30 check whether insertion is possible


11. insert 3 records in dept and display all records from dept

12. use rollback command check what happens


13. do the following
insert row in emp with empno 100
insert row in emp with empno 101
insert row in emp with empno 102
add savepoint A
insert row in emp with empno 103
insert row in emp with empno 104
insert row in emp with empno 105
add savepoint B
delete emp with empno 100
delete emp with emp no 104
rollback upto svaepoint B

check what all records will appear in employee table rollback upto A
check what all records will appear in employee table
commit all changes
check what all records will appear in employee table check whether you can
roll back the contents.
14. create a procedure getMin(deptno,minsal) to find minimum salary of given
table.
PLSQL ASSIGNMENT
Solve the following Loops example
1. Print the following patterns using loop :
a.
*
**
***
****
b.
*
***
*****
***
*
c.
1010101
10101
101
1

d.
1
12
123
1234
12345
1.
2. write a procedure to insert record into employee table. the procedure
should accept empno, ename, sal, job, hiredate as input parameter write insert
statement inside procedure insert_rec to add one record into table
create procedure insert_rec(peno int,pnm varchar(20),psal decimal(9,2),pjob
varchar(20),phiredate date) begin insert into
emp(empno,ename,sal,job,hiredate) values(peno,pnm,psal,pjob,phiredate)
end//
3. write a procedure to delete record from employee table. the procedure
should accept empno as input parameter. write delete statement inside
procedure delete_emp to delete one record from emp table
4. write a procedure to display empno,ename,deptno,dname for all employees
with sal > given salary. pass salary as a parameter to procedure
5. write a procedure to find min,max,avg of salary and number of employees in
the given deptno. deptno --→ in parameter min,max,avg and count ---→ out
type parameter execute procedure and then display values min,max,avg and
count

6. write a procedure to display all pid,pname,cid,cname and salesman


name(use product,category and salesman table)
7. write a procedure to display all vehicles bought by a customer. pass cutome
name as a parameter.(use vehicle,salesman,custome and relation table)
8. Write a procedure that displays the following information of all emp
Empno,Name,job,Salary,Status,deptno Note: - Status will be (Greater, Lesser or
Equal) respective to average salary of their own department. Display an error
message Emp table is empty if there is no matching record.
9. Write a procedure to update salary in emp table based on following rules.
Exp< =35 then no Update Exp> 35 and <=38 then 20% of salary Exp> 38 then
25% of salary
10. Write a procedure and a function. Function: write a function to calculate
number of years of experience of employee.(note: pass hiredate as a
parameter) Procedure: Capture the value returned by the above function to
calculate the additional allowance for the emp based on the experience.
Additional Allowance = Year of experience x 3000 Calculate the additional
allowance and store Empno, ename,Date of Joining, and Experience in years
and additional allowance in Emp_Allowance table. create table
emp_allowance( empno int, ename varchar(20), hiredate date, experience int,
allowance decimal(9,2));
11. Write a function to compute the following. Function should take sal and
hiredate as i/p and return the cost to company. DA = 15% Salary, HRA= 20% of
Salary, TA= 8% of Salary. Special Allowance will be decided based on the service
in the company. < 1 Year Nil >=1 Year< 2 Year 10% of Salary >=2 Year< 4 Year
20% of Salary >4 Year 30% of Salary
12. Write query to display empno,ename,sal,cost to company for all
employees(note: use function written in question 10)

Q2. Write trigger


1. Write a tigger to store the old salary details in Emp _Back (Emp _Back has
the same structure as emp table without any constraint) table. (note :create
emp_back table before writing trigger) ----- to create emp_back table create
table emp_back( empno int, ename varchar(20), oldsal decimal(9,2), newsal
decimal(9,2) ) (note : execute procedure written in Q8 and check the entries in
EMP_back table after execution of the procedure)
2. Write a trigger which add entry in audit table when user tries to insert or
delete records in employee table store empno,name,username and date on
which operation performed and which action is done insert or delete. in
emp_audit table. create table before writing trigger. create table empaudit(
empno int; ename varchar(20), username varchar(20); chdate date; action
varchar(20) );
3. Create table vehicle_history. Write a trigger to store old vehicleprice and
new vehicle price in history table before you update price in vehicle table
(note: use vehicle table). create table vehicle_history( vno int, vname
varchar(20), oldprice decimal(9,2), newprice decimal(9,2), chdate date,
username varchar(20) );
MONGO DB ASSIGNMENT 1
Create a Employee Collection add 5 documents: Example:
{emono:111,ename:”Deepali
Vaidya”,sal:40000.00,dept:{deptno:12,dname:,”Hr”,dloc:”Mumbai},
Desg:”Analyst”,mgr:{name:”Satish”,num:111},project:[{name:”Project
1”,Hrs:4},{name:”project- 2”,Hrs:4}]}

1.All Employee’s with the desg as ‘CLERK’ are now called as (AO) Administrative
Officers. Update the Employee collection for this.

2. Change the number of hours for project-1 to 5 for all employees with
designation analyst.
3. Add 2 projects project-3 and project-4 for employee whose name starts with
”Deep” with 2 hrs
db.emp.update({name:/^Deep/},{$push:{project:{$each:[{name:'project
3',Hrs:2},{name:'project-4',Hrs:2}]}}}, {multi:true})

4. Add bonus rs 2000 for all employees with salary > 50000
5. add bonus 1500 if salary 30000

6. add bonus 1000 if salary <=30000

7. Change manager name to Tushar for all employees whose manager is


currently “satish” And manager number to 3333

8. Increase salary of all employees from “purchase department” by 15000


9. Decrease number of hrs by 2 for all employees who are working on project-2

10. Delete project-2 from all employee document if they are working on the
project for 4 hrs. db.emp.update({},{$pull:{“project.name”:”project-
2”,”project.Hrs”:4}},{multi:true}) or
db.Emp.update({},{$pull:{project:{name:'project-2',Hrs:4}}},{multi:true}) or
db.emp.update({},{$pull:{“project:{$elemMatch:{name:”project-
2”,”Hrs”:4}},{multi:true})

11. Change the salary of employees to 10000 only if their salary is < 10000
12. Increase bonus of all employees by 500 if the bonus is < 20000 or if
employee belong to sales department

13. Add 2 new project at position 2 for all employees with designation analyst
or salary is equal to either 30000 or 33000 or 35000

14. Delete last project of all employees with department name is “HR” and if
the location is Mumbai

15. Change designation of all employees to senior programmer if they are


working on name:”Project-1” for 4 hrs
16. Add list of hobbies in all employees document whose manager is Rajan or
Revati

17. Add list of skillset in all employee documents who are working on project-4
for 3 hrs or on project-3 for 4 hrs

18. Add a new hobby as blogging at 3 position in hobbies array for all
employess whose name starts with R or p and ends with j or s

19. Increase salary by 10000 for all employees who are working on project-2 or
project-3 or project-1

20. Decrease bonus by 1000 rs And increase salary by 1000rs for all employees
whose department location is Mumbai
21. Remove all employees working on project-4

22. Replace document of employee with name “Deepak to some new


document

23. Change skill python to python 3.8 for all employees if python is there in the
skillset
24. Add 2 skills MongoDb and Perl at the end of skillset array for all employees
who are working at Pune location

25. Delete first hobby from hobby array for all employees who are working on
project-1 or project-2

26. Delete last hobby from hobbies array for all employees who are working on
project which is at 2 nd position in projects array for 4 hrs

27. Add 2 new projects at the end of array for all employees whose skillset
contains Perl or python
28. Change hrs to 6 for project-1 for all employees if they working on the
project-1 for < 6 hrs. otherwise keep the existing value.

MONGO DBASSIGNMENT 2
1. Write a MongoDB query to display all the documents in the collection
restaurants
2. Write a MongoDB query to display the fields restaurant_id, name, borough
and cuisine for all the documents in the collection restaurant.
3. Write a MongoDB query to display the fields restaurant_id, name, borough
and cuisine, but exclude the field _id for all the documents in the collection
restaurant.
4. Write a MongoDB query to display the fields restaurant_id, name, borough
and zip code, but exclude the field _id for all the documents in the collection
restaurant.
5. Write a MongoDB query to display all the restaurant which is in the borough
Bronx
6. Write a MongoDB query to display the first 5 restaurant which is in the
borough Bronx.
7.Write a MongoDB query to display the next 5 restaurants after skipping first 5
which are in the borough Bronx.
8. Write a MongoDB query to find the restaurants who achieved a score more
than 90.
9. Write a MongoDB query to find the restaurants that achieved a score, more
than 80 but less than 100.
10. Write a MongoDB query to find the restaurants which locate in latitude
value less than 95.754168.
11. Write a MongoDB query to find the restaurants that do not prepare any
cuisine of 'American' and their grade score more than 70 and latitude less than
-65.754168.
12. Write a MongoDB query to find the restaurants which do not prepare any
cuisine of 'American' and achieved a score more than 70 and located in the
longitude less than 65.754168.
13. Write a MongoDB query to find the restaurants which do not prepare any
cuisine of 'American ' and achieved a grade point 'A' not belongs to the
borough Brooklyn. The document must be displayed according to the cuisine in
descending order.
14. Write a MongoDB query to find the restaurant Id, name, borough and
cuisine for those restaurants which contain 'Wil' as first three letters for its
name.
15. Write a MongoDB query to find the restaurant Id, name, borough and
cuisine for those restaurants which contain 'ces' as last three letters for its
name.
16. Write a MongoDB query to find the restaurant Id, name, borough and
cuisine for those restaurants which contain 'Reg' as three letters somewhere in
its name.
17. Write a MongoDB query to find the restaurants which belong to the
borough Bronx and prepared either American or Chinese dish.
18. Write a MongoDB query to find the restaurant Id, name, borough and
cuisine for those restaurants which belong to the borough Staten Island or
Queens or Bronxor Brooklyn.
19. Write a MongoDB query to find the restaurant Id, name, borough and
cuisine for those restaurants which are not belonging to the borough Staten
Island or Queens or Bronxor Brooklyn.
20. Write a MongoDB query to find the restaurant Id, name, borough and
cuisine for those restaurants which achieved a score which is not more than 10.
21. Write a MongoDB query to find the restaurant Id, name, borough and
cuisine for those restaurants which prepared dish except 'American' and
'Chinees' or restaurant's name begins with letter 'Wil'.
22. Write a MongoDB query to find the restaurant Id, name, and grades for
those restaurants which achieved a grade of "A" and scored 11 on an ISODate
"2014-08-11T00:00:00Z" among many of survey dates
23. Write a MongoDB query to find the restaurant Id, name and grades for
those restaurants where the 2nd element of grades array contains a grade of
"A" and score 9 on an ISODate "2014-08-11T00:00:00Z".
24. Write a MongoDB query to find the restaurant Id, name, address and
geographical location for those restaurants where 2nd element of coord array
contains a value which is more than 42 and upto 52
25. Write a MongoDB query to arrange the name of the restaurants in
ascending order along with all the columns.
26. Write a MongoDB query to arrange the name of the restaurants in
descending along with all the columns.
27. Write a MongoDB query to arranged the name of the cuisine in ascending
order and for that same cuisine borough should be in descending order.
28. Write a MongoDB query to know whether all the addresses contains the
street or not.
29. Write a MongoDB query which will select all documents in the restaurants
collection where the coord field value is Double.
30. Write a MongoDB query which will select the restaurant Id, name and
grades for those restaurants which returns 0 as a remainder after dividing the
score by 7.
31. Write a MongoDB query to find the restaurant name, borough, longitude
and attitude and cuisine for those restaurants which contains 'mon' as three
letters somewhere in its name.
32. Write a MongoDB query to find the restaurant name, borough, longitude
and latitude and cuisine for those restaurants which contain 'Mad' as first three
letters of its name.

You might also like