Complete Dbms 1and 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Lab Plan

Course: B.C.A. Semester – II BATCH:


Subject: DATABASE MANAGEMENT SYSTEMS Lab Subject Code:
Faculty Name: Ms. Meena Sachdeva Total Session: 36

Sr. Topic Session


No.
1 Write a query to create a table, insert data into a
table, describe the table schema, retrieve the data S1,S2
from table using select command.
2 Write a query for deletion, updation, truncating a
table, dropping the table, aliasing the column name S3,S4
while retrieving the data.
3 Creating a table from another table with or without
populating data, renaming the table name,
S5,S6
modifying the structure of the table using Alter
command.
4 Create the Location , Department, Job & Employee
S7,S8
tables, Insert data into the tables
5 Do the following Queries based on the above
tables-

Simple Queries:

1.List all the employee details


2.List all the department details
3.List all job details
4.List all the locations
5.List out first name,last name,salary, commission S9,S10,S11
for all employees
6. List out employee_id,last name, department id for
all employees and rename employee id as “ID of
the employee”, last name as “Name of the
employee”, department id as “department ID”
7. List out the employees anuual salary with their
names only.
Where Conditions:
1. List the details about “SMITH”
2. List out the employees who are working in
department 20
3. List out the employees who are earning salary
between 3000 and 4500
4. List out the employees who are working in
department 10 or 20
5. Find out the employees who are not working in
department 10 or 30
6. List out the employees whose name starts with
“S”
7. List out the employees whose name start with “S”
and end with “H”
8. List out the employees whose name length is 4
and start with “S”
9. List out the employees who are working in
department 10 and draw the salaries more than
3500
10. list out the employees who are not receiving
commission.
6 Order By Clause:

1. List out the employee id, last name in ascending


order based on the employee id.
2. List out the employee id, name in descending
order based on salary column
3. list out the employee details according to their
last_name in ascending order and salaries in
descending order
4. list out the employee details according to their
last_name in ascending order and then on
department_id in descending order.
Group By & Having Clause:

1. How many employees who are working in


different departments wise 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
S12,S13,S14
salary, average salaries of the employees.
4. List out the no.of employees joined in every
month in ascending order.
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 four
employees.
7. How many employees in January month.
8. How many employees who are joined in January
or September month.
9. How many employees who are joined in 1985.
10. How many employees joined each month in
1985.
11. How many employees who are joined in March
1985.
12. Which is the department id, having greater than
or equal to 3 employees joined in April 1985.
7 Sub-Queries

1. Display the employee who got the maximum


salary.
2. Display the employees who are working in Sales
department
3. Display the employees who are working as
“Clerk”.
4. Display the employees who are working in “New
York”
5. Find out no.of employees working in “Sales”
S15,S16,S17
department.
6. Update the employees salaries, who are working
as Clerk on the basis of 10%.
7. Delete the employees who are working in
accounting department.
8. Display the second highest salary drawing
employee details.
9. Display the Nth highest salary drawing employee
details
8
Joins
Simple join

1. List our employees with their department names


2. Display employees with their designations (jobs)
3. Display the employees with their department
name and regional groups.
4. How many employees who are working in
different departments and display with
department name.
5. How many employees who are working in sales
department.
6. Which is the department having greater than or S18,S19,S20
equal to 5 employees and display the department
names in ascending order.
7. How many jobs in the organization with
designations.
8. How many employees working in “New York”.
Non – Equi Join:

1. Display employee details with salary grades.


2. List out the no. of employees on grade wise.

3. Display the employ salary grades and no. of


employees between 2000 to 5000 range of salary.

9 Self Join:

1. Display the employee details with their manager


names.
2. Display the employee details who earn more than
their managers salaries.
3. Show the no. of employees working under every S21,S22,S23
manager.

Outer Join:

1. Display employee details with all departments.


2. Display all employees in sales or operation
departments.
Set Operators:

1. List out the distinct jobs in Sales and Accounting


Departments.
2. List out the ALL jobs in Sales and Accounting
Departments.
3. List out the common jobs in Research and
Accounting Departments in ascending order.
10 Sub-Query operators: (ALL,ANY,SOME,EXISTS)

1. List out the employees who earn more than every


employee in department 30.
2. List out the employees who earn more than the
lowest salary in department 30.
3. Find out whose department has not employees.
4. Find out which department does not have any
S24.S25,S26
employees.

Co-Related Sub Queries:

1. Find out the employees who earn greater than the


average salary for their department.
11 Create a View

1. having emp_ssn , emp_name,


emp_city,emp_state,emp_dob,emp_gndr,emp_dpt_no
from employee table.
2. Having emp_ssn , emp_name,emp_dpndt_name &
dpndt_dob from employee table S27,S28,S29
3. Having dept_no,dept_name,prjct_no,prjct_name &
prjct_lctn.
4. Having dept_no,dept_name,prjct_no,prjct_name &
prjct_lctn having either Production or Headquarter as
department

12 1. Write a program to implement different types of


cursor

2. Write a program to implement different types of


S30,S31
Triggers.

13 1. Write a program in PL/SQL to print the table of a number.

2. Write a program in PL/SQL to print the sum from 1 to 100.


S32,S33,S34
3. Write a program in PL/SQL to check whether a number is
even or odd.

14 1. Write a program in PL/SQL to print the reverse of a


number.
2. Write a program in PL/SQL to calculate the area of a
Square.
S35,S36
3. Write a program in PL/SQL to Calculate the area of a
Square & stored in a table.
4. Write a program in PL/SQL to print the addition of two
numbers.
5. Write a program in PL/SQL to update the salary.

SOLUTION OF QUERIES

Q.1 Write a query to create a table, insert data into a table, describe the
table schema, retrieve the data from table using select command.

⮚ Creating a table-

create table student(roll_no number,name varchar(255),city


varchar(255),mobile_no number);

⮚ Inserting data into a table-

insert into student values(1,'aakash','lucknow','8303378675');

⮚ Deleting records from table-

a. for deleting all records in table:


delete from student;
b. for deleting specific record in table:
delete from student where name='aakash';

⮚ Describing Schema of a table-

describe student;

⮚ Retrieving data from a table-

a. for retrieving whole data from table:


select * from students;

b. for retrieving specific data from table:


select * from students where city='lucknow';
Q.2 Write a query for deletion, updation, truncating a table, dropping the
table, aliasing the column name while retrieving the data.

⮚ Updating a table-

update student set city='noida' where name='aakash';

⮚ Truncating a table-

truncate table student;

⮚ Dropping a table-

drop table student;


⮚ Aliasing column name while retrieving data from a table-

select city as “hometown” from student;

You might also like