0% found this document useful (0 votes)
35 views32 pages

Index S. No. Title of Practical Date NO. Sign.: Harshit 2820410 Database Management Systems Lab

The document is an index for a database management systems lab manual. It lists 10 practical assignments completed by Harshit with student ID 2820410. The practicals cover topics like adding/deleting records, queries, integrity constraints, arithmetic/relational operations, group by/having clauses, views involving joins, triggers and a stored procedure to calculate income tax.

Uploaded by

tyagiharshit0098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views32 pages

Index S. No. Title of Practical Date NO. Sign.: Harshit 2820410 Database Management Systems Lab

The document is an index for a database management systems lab manual. It lists 10 practical assignments completed by Harshit with student ID 2820410. The practicals cover topics like adding/deleting records, queries, integrity constraints, arithmetic/relational operations, group by/having clauses, views involving joins, triggers and a stored procedure to calculate income tax.

Uploaded by

tyagiharshit0098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Harshit

Database Management Systems Lab 2820410

INDEX

S. No. TITLE OF PRACTICAL DATE PAGE SIGN.


NO.
1 Create a database and write the programs to carry out the
following operation:
⚫ Add, Delete and Modify a record in a database
02 Mar 22 3-8
⚫ Generate Queries
⚫ Data Operations
⚫ List all the records of database in ascending order.
2 To perform various integrity constraints on relational
09 Mar 22 9-10
database
3. Create a database and perform the following operations:-
⚫ Arithmetic and Relational Operations.
06 April 22 11-17
⚫ Group By & Having clauses.
⚫ Like predicate for pattern matching in database.
4. Create a view to display details of employees working
13 April 22 18-19
on more than one project.
5. Create a view to display details of employees not working on
20 April 22 20-21
any project.
6. Using two tables create a view which shall perform natural
27 April 22 22-24
join, equi join, outer joins.
7. Create a view to display details of employees working on one
18 April 22 25-26
Project.
8. Write a Trigger for After Insertion, Deletion and Updation
25 May 22 27-29
Process.
9. Write a Trigger for Before Insertion, Deletion and Updation
25 May 22 30-31
Process.
10. Write a procedure for computing income tax of a employee
On the basis of following conditions:-

1.if gross pay <= 40,000 then I.T rate is 0%


2.if gross pay >40,000 but <60,000 then I.T. rate is 10%
01 June 22 32-33
3.if gross pay>60,000 but <1,00,000 then I.T. rate is 20%
4.if gross pay >1,00,000 then I.T. rate is 30%

For this purpose create a table with name, ssn , gross salary
and income tax of the employee

2
Harshit
Database Management Systems Lab 2820410

Practical No. 1
Problem Statement:Create a database and write the programs to carry out the
following operation:
⚫ Add, Delete and modify a record in the database.
⚫ Generate queries
⚫ Data Operations
⚫ List all the records of database in ascending order

Table Used:

create table student(C_Id NUMBER(3),S_Name char(20), Gender char(2),Age number(2), Course


char(20))

insert into student values('263', 'Sachin', 'M', '19', 'CSE')


insert into student values('265', 'Yash', 'M', '19', 'IT')
insert into student values('352', 'Harshit', 'M', '19', 'ECE')
insert into student values('346', 'Raman', 'M', '20', 'IT')
insert into student values('292', 'Arjun', 'M', '19', 'CSE')
insert into student values('279', 'Ishita', 'F', '21', 'CSE')
insert into student values('389', 'Shalu', 'F', '18', 'ECE')
select * from student

Add, Delete and modify a record in the database.


Command: INSERT
Syntax-
insert into <table name> values (<expression1>,<expression2>)

Example-
insert into student values('387','Meenu','F','17','MCA')

3
Harshit
Database Management Systems Lab 2820410

Output-

Command:UPDATE
Syntax-
update tablename set field=values where condition

Example-
update student set Course = ‘MCA’ where C_ID = ‘382’

Output-

After updating-

Command:DELETE

Syntax-
Delete from <table-name>

Example-

4
Harshit
Database Management Systems Lab 2820410

delete from student where Course = 'MCA'


Output-

After Deletion-

Generate queries
select * from student

Output-

5
Harshit
Database Management Systems Lab 2820410

select S_Name,Course from student where C_Id BETWEEN 292 and 311
Output

Data Operations

Command- AND

select S_Name, Course from student where C_ID = 223 and Age = 19

Output-

Command -OR
select S_Name from student where C_ID = 279 or Age = 19

6
Harshit
Database Management Systems Lab 2820410

Output-

Command –NOT

select S_Name,Course from student where NOT Age = 19

Output-

List all the records of database in ascending order

Command –ORDER BY
select *from student order by C_Id

7
Harshit
Database Management Systems Lab 2820410

Output-

8
Harshit
Database Management Systems Lab 2820410

Practical No. 2
Problem Statement:To perform various integrity constraints on relational database.
Primary Key Constraints
Create Table Employee345(EID Number(4) primary key , Name char(20), Salary number(10));
Insert into Employee345 Values('302' ,'Harshit' , '60000' )
insert into Employee345 Values('332' ,'Yash' , '24000')
insert into Employee345 Values('346' ,'Shiv' , '14000')
insert into Employee345 Values('316' ,'Deepak' ,'16000')
insert into Employee345 Values('366' ,'Sunny' , '48000')

Select * from Employee345

Output-

Insert into Employee345 values('', 'pappu','40000')

Insert into Employee345 values('302', 'bindhu','50000')

9
Harshit
Database Management Systems Lab 2820410

Foreign Key Constraints


create table project(DID varchar(5) primary key, D_NAME char(10))
insert into project values('302',' CSE')
insert into project values('332','BCA')
insert into project values('346','Cyber')
insert into project values('316','BBA')
insert into project values('366','MCA')

select * from project

insert into Deptt1 values ('303' , 'MBA')

10
Database Management Systems Lab Harshit
2820410

Practical No. 3

Problem Statement:Create a database and perform the following operations:-


1. Arithmetic and Relational Operations
2. Group By and Having clause
3. Like predicate for pattern matching in database

Table creation:

create table Employe(E_ID number(5) primary key, Name char(20), Age number(2), Salary
number(20))
insert into Employe values('311', 'pulkit', '19', '45000')
insert into Employe values('123', 'asmit', '19', '40000')
insert into Employe values('321', 'harshit', '20', '35000')
insert into Employe values('890', 'chakshu', '21', '37000')
insert into Employe values('654', 'Ridhi', '20', '30000')
insert into Employe values('320', 'Priya', '21', '33000')
select * from Employe

Output-

Arithmetic Operations-

Add Operator (+)

Example-
update Employe set Salary = Salary + 500
select * from Employe

11
Database Management Systems Lab Harshit
2820410
Output-

Subtract Operator (-)

Example-
update Employe set Salary = Salary - 400
select * from Employe

Output-

Multiply Operator (*)

Example-

update Employe set Salary = Salary * 2


select * from Employe

12
Database Management Systems Lab Harshit
2820410
Output-

Divide Operator (/)

Example-

update Employe set Salary = Salary / 2


select * from Employe

Output-

Relational Operations-

Equal Operator (=)

Example-
select * from Employe where Salary = 45100

13
Database Management Systems Lab Harshit
2820410
Output-

Less than Operator (<)

Example-
select * from Employe where Salary <45100

Output-

Greater than Operator (>)

Example-
select * from Employe where Salary >35100

Output-

14
Database Management Systems Lab Harshit
2820410

Greater than or equal to (>=)

Example-
select * from Employe where Salary >= 40000

Output-

Less than or equal to (<=)

Example-
select * from Employe where Salary <= 40000

Output-

Not equal to (<>)

Example-
select * from Employe where Salary <>30100

15
Database Management Systems Lab Harshit
2820410
Output-

Group By Clause-

Example-
select count(Name), Age from Employe group by Age

Output-

HavingClause-

Example-
select count(Name), Age from Employe group by Age having count(E_ID)>=2

Output-

16
Database Management Systems Lab Harshit
2820410

Like predicate for pattern matching in database-

Example-

select Name from Employe where Name like 'P%'

Output-

17
Database Management Systems Lab Harshit
2820410

Practical No. 4

Problem Statement:Create a view to display details of employees working on more


than one project.
Table Creation:

select * from Company

select * from Project

Command:

create view MultiProj as select Company.Name, Project1.Project_Name from Company inner join project1 on
company.EID = project1.EID where project1.EID in
( select EID from project1 group by EID having Count(EID)>1)

18
Database Management Systems Lab Harshit
2820410
Output:

select * from MultiProj

Output:

19
Database Management Systems Lab Harshit
2820410
Practical No. 5

Problem Statement:Create a view to display details of employees not working on any


project.

select * from Company

select * from Project

Command:

create view NoProj as select Company.SSN ,Company.Name from Company left join Project on
company.ssn = project.ssn where project.ssn is NULL order by Company.ssn

20
Database Management Systems Lab Harshit
2820410

Output:

Command:

select * from NoProj

21
Database Management Systems Lab Harshit
2820410

Practical No. 6
Problem Statement:Using two tables create a view which shall perform natural join,
equi join, outer joins.

select * from Emp1


Output:

select * from Dept1


Output:

Full Join:

Select Emp1.E_Id , Emp1.Name , Emp1.Salary , Emp1.DID, Dept1.DID , Dept1.Dept_Name from


Emp1 full join Dept1 on Emp1.DID = Dept1.DID

22
Database Management Systems Lab Harshit
2820410

Output:

Inner Join:

Select Emp1.EID , Emp1.Name , Emp1.Salary , Emp1.DID, Dept1.DID , Dept1.Dept_Name from


Emp1 inner join Dept1 on Emp1.DID = Dept1.DID
Output:

Left Join:

Select Emp1.EID , Emp1.Name , Emp1.Salary , Emp1.DID, Dept1.DID , Dept1.Dept_Name from


Emp1 left join Dept1 on Emp1.DID = Dept1.DID

23
Database Management Systems Lab Harshit
2820410

Output:

Right Join:

Select Emp1.EID , Emp1.Name , Emp1.Salary , Emp1.DID, Dept1.DID , Dept1.Dept_Name from


Emp1 right join Dept1 on Emp1.DID = Dept1.DID
Output:

24
Database Management Systems Lab Harshit
2820410

Practical No. 7

Problem Statement: :Create a view to display details of employees working on one


Project.
Table Creation:

create table Com1(E_ID number(5) primary key, Name char(20), age number(5))
insert into Com1 values (‘311’, ‘Tushar’,’10’)
insert into Com1 values (‘282’, ‘Pankaj’,’20’)
insert into Com1 values (‘264’, ‘Aman’,’70’)
insert into Com1 values (‘303’, ‘Mukul’,’90’)
insert into Com1 values (‘933’, ‘Divya’,’50’)
insert into Com1 values (‘306’, ‘Amit’,’30’)

select * from Com1

Output:

Table Creation:

create table Proj1 (E_ID number(5) references Com1(E_ID),Proj_NO number(3),Proj_Name


char(10))
insert into Proj1 values ('311','1','Gaming')
insert into Proj1 values ('282','3','Security')
insert into Proj1 values ('264','2','Hacking')
insert into Proj1 values ('282','4','Program')
insert into Proj1 values ('264','1','Gaming')
insert into Proj1 values ('933','2','Hacking')

select * from Proj1

25
Database Management Systems Lab Harshit
2820410

Output:

Command:

Create view Oneproject1 as Select Com1.Name , Proj1.Proj_Name from Com1 Inner join Proj1 on
Com1.E_ID=Proj1.E_ID where Proj1.E_ID not in (Select E_ID from proj1 group by E_ID having
count(E_ID)>1)

Output:

Command:

select * from OneProject1

Output:

26
Database Management Systems Lab Harshit
2820410

Practical No. 8
Problem Statement: Write a Trigger for After Insertion, Deletion and
Updation Process

Trigger After Insertion, Deletion and Updation Process.


Create table students23 (name char(10), Roll_No number(5) primary key, Balance number(5))
insert into students23 values('asmit','311', '30000')
insert into students23 values('chakshu','282', '50000')
insert into students23 values('harshit','264', '70000')
insert into students23 values('Amit','306', '80000')
insert into students23 values('Mukul','303', '90000')

select * from students23

Output:

Create table security420 (name char(10), Roll_No number(5), Balance number(5),operator char(8),
user_info char(15), date_and_time_info timestamp)

Output:

Create or replace trigger trig543 after insert or delete or update on students23

27
Database Management Systems Lab Harshit
2820410
for each row
declare
user_info char(15);
operator char(8);
date_and_time_info timestamp;
begin
if updating then
operator:='Update';
user_info:= user;
date_and_time_info :=SYSTIMESTAMP;
end if;
if deleting then
operator:='Delete';
user_info:= user;
date_and_time_info :=SYSTIMESTAMP;
end if;
if inserting then
operator:='Insert';
user_info:= user;
date_and_time_info :=SYSTIMESTAMP;
end if;

insert into security420values


(:old.name,:old.roll_no,:old.balance,operator,user_info,date_and_time_info);
end

Output:

update students23 set name = 'Mukul' where name = 'Sharma'

Output:

28
Database Management Systems Lab Harshit
2820410

insert into students23 values ('Divya','933', '20000')

Output:

delete from students23 where name = 'Amit'

Output:

select * from security420

Output:

29
Database Management Systems Lab Harshit
2820410

Practical No. 9

Problem Statement:Write trigger for before insertion, deletion and updation process.

Table Creation: Table Student5


Create table student5(Name varchar2(20),Roll_no varchar2(9) ,Balance
varchar2(10)); Insert into student5 values('Harshit','302','1550');
Select * from student5;

Trigger Creation:
Create or replace trigger trig2 before insert or update or delete on student5 for
each row begin
if :new.balance<=0 then
raise_application_error(-20003,'salary cannot be less than zero');
end if;
End;

30
Database Management Systems Lab Harshit
2820410

Command : Insertion
Insert into student5 values('Tim','273','-256');

Command :Updation
Update student5 set balance='-8500' where roll_no='302'

31
Database Management Systems Lab Harshit
2820410

Practical No. 10
Problem Statement:Write a procedure for computing income tax of employee on the basic of
following conditions:-
1. if gross pay<=40,0000 then I.T rate is 0%.
2. if gross pay>40,0000 but <60000 then I.T rate is 10%.
3. if gross pay>60,0000 but <1,00,0000 then I.T rate is 20%.
4. if gross pay>1,00,0000 then I.T rate is 30%.
For this purpose create a table with name, ssn, gross salary and income tax of the
employee.

Command :

Create table Server3 (SSN number(4),Name char(10),Salary Number(10),Tax number(10,3));


Create or replace procedure incometax(SSN in number,name in char,salary in number)
is tax number(10,3);
begin
if(salary<=400000)then
tax:=0.000;
end if;
if(salary>400000 and salary<=600000)then
tax:=(10*salary)/100;
end if;
if(salary>600000 and salary<=1000000)then
tax:=(20*salary)/100;
end if;
if(salary>1000000 )then
tax:=(30*salary)/100;
end if;
Insert into server3values(SSN,Name,Salary,tax);
end;

32
Database Management Systems Lab Harshit
2820410

To be executed on Command Line:

execute incometax('302' , 'Harshit' ,'300000');


execute incometax('6872' , 'Sam' ,'700000');
execute incometax('7844' , 'John' ,'1100000');
execute incometax('9852' , 'Peter' ,'500000');
commit;
Select * from server3

33

You might also like