Index S. No. Title of Practical Date NO. Sign.: Harshit 2820410 Database Management Systems Lab
Index S. No. Title of Practical Date NO. Sign.: Harshit 2820410 Database Management Systems Lab
INDEX
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:
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
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
Output-
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')
Output-
9
Harshit
Database Management Systems Lab 2820410
10
Database Management Systems Lab Harshit
2820410
Practical No. 3
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-
Example-
update Employe set Salary = Salary + 500
select * from Employe
11
Database Management Systems Lab Harshit
2820410
Output-
Example-
update Employe set Salary = Salary - 400
select * from Employe
Output-
Example-
12
Database Management Systems Lab Harshit
2820410
Output-
Example-
Output-
Relational Operations-
Example-
select * from Employe where Salary = 45100
13
Database Management Systems Lab Harshit
2820410
Output-
Example-
select * from Employe where Salary <45100
Output-
Example-
select * from Employe where Salary >35100
Output-
14
Database Management Systems Lab Harshit
2820410
Example-
select * from Employe where Salary >= 40000
Output-
Example-
select * from Employe where Salary <= 40000
Output-
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
Example-
Output-
17
Database Management Systems Lab Harshit
2820410
Practical No. 4
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:
Output:
19
Database Management Systems Lab Harshit
2820410
Practical No. 5
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:
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.
Full Join:
22
Database Management Systems Lab Harshit
2820410
Output:
Inner Join:
Left Join:
23
Database Management Systems Lab Harshit
2820410
Output:
Right Join:
24
Database Management Systems Lab Harshit
2820410
Practical No. 7
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’)
Output:
Table Creation:
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:
Output:
26
Database Management Systems Lab Harshit
2820410
Practical No. 8
Problem Statement: Write a Trigger for After Insertion, Deletion and
Updation Process
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:
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;
Output:
Output:
28
Database Management Systems Lab Harshit
2820410
Output:
Output:
Output:
29
Database Management Systems Lab Harshit
2820410
Practical No. 9
Problem Statement:Write trigger for before insertion, deletion and updation process.
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 :
32
Database Management Systems Lab Harshit
2820410
33