NAGAJI INSTITUTE OF TECHNOLOGY & MANAGEMENT
DEPARTMENT
OF
COMPUTER SCIENCE AND ENGINEERING
LABORATORY MANUAL
For
DATABASE MANAGEMENT SYSTEM
SUBJECT CODE CS 503
Submitted To : -
Ms. Archana Acharya
Asst. Professor CSE
Submitted By : Sanjay Dayal Kushwah
B.E. (CSE Vth Semester)
Enroll No. 0917CS1410__
INDEX
SR
NO.
EXPERIMENT
DATE
01
To create a table of employees for
various departments.
5/09/16
02
To delete duplicate record from the
table.
12/09/16
03
To display the alternate records or
rows from the table.
26/09/16
04
To find the third highest paid and the
third lowest paid salary.
3/10/16
05
To display the 3rd, 4th and 6th rows
from the table.
17/10/16
06
To display the employees name ,
which start with R and S.
24/10/16
07
Updating the multiple rows in using
single update statement.
7/11/16
08
To display the employees who were
hired during the first half of the month.
28/11/16
SIGNATURE
INDEX
SR
NO.
EXPERIMENT
DATE
09
To display Employee name , job and
salary column from the table.
5/12/16
10
To desing an E-R diagram for hospital
management system.
12/12/16
SIGNATURE
Experiment 1
Aim To create a table of employees for various departments.
create table Emp
(
recordNo int,
empID int,
eName varchar(10),
eSurname varchar(10),
age int,
sex char(1),
job varchar(15),
hiredate date,
salary number(8,2),
deptNo number(3,0),
mobNo int
);
Inserting the values into Emp table
insert into Emp
values ( 1,101,'Sanjay','Dayal',20,'M','Programmer',to_date('05-12-2016','dd-mmyyyy'),30000,10,889805);
insert into Emp
values ( 2,102,'Shahid','Pathan',22,'M','Operator',to_date('10-12-2016','dd-mmyyyy'),20000,20,999805);
insert into Emp
values ( 3,103,'Priya','Vyas',20,'F','Secretary',to_date('16-12-2016','dd-mmyyyy'),15000,10,999111);
insert into Emp
values ( 4,104,'Ajay','Dholpuriya',23,'M','Manager',to_date('01-12-2016','dd-mmyyyy'),35000,20,454890);
insert into Emp
values ( 5,105,'Riya','Sen',25,'F','DBA',to_date('20-12-2016','dd-mmyyyy'),70000,10,909123);
insert into Emp
values ( 6,111,'Shubham','Kushwah',30,'M','CEO',to_date('12-11-2016','dd-mmyyyy'),100000,20,555123);
insert into Emp
values ( 7,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 9,170,'Kajal','Gupta',25,'F','Receptionist',to_date('27-12-2016','dd-mmyyyy'),10000,20,555626);
select *from Emp
Experiment 2
Aim To delete duplicate record from the table.
create table Emp
(
recordNo int,
empID int,
eName varchar(10),
eSurname varchar(10),
age int,
sex char(1),
job varchar(15),
hiredate date,
salary number(8,2),
deptNo number(3,0),
mobNo int
);
Inserting the values into Emp table
insert into Emp
values ( 1,101,'Sanjay','Dayal',20,'M','Programmer',to_date('05-12-2016','dd-mmyyyy'),30000,10,889805);
insert into Emp
values ( 2,102,'Shahid','Pathan',22,'M','Operator',to_date('10-12-2016','dd-mmyyyy'),20000,20,999805);
insert into Emp
values ( 3,103,'Priya','Vyas',20,'F','Secretary',to_date('16-12-2016','dd-mmyyyy'),15000,10,999111);
insert into Emp
values ( 4,104,'Ajay','Dholpuriya',23,'M','Manager',to_date('01-12-2016','dd-mmyyyy'),35000,20,454890);
insert into Emp
values ( 5,105,'Riya','Sen',25,'F','DBA',to_date('20-12-2016','dd-mmyyyy'),70000,10,909123);
insert into Emp
values ( 6,111,'Shubham','Kushwah',30,'M','CEO',to_date('12-11-2016','dd-mmyyyy'),100000,20,555123);
insert into Emp
values ( 7,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 8,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 9,170,'Kajal','Gupta',25,'F','Receptionist',to_date('27-12-2016','dd-mmyyyy'),10000,20,555626);
select *from Emp
Deleting the duplicate row from the table emp
delete from emp
where recordno = 7;
Experiment 3
Aim To display the alternate records or rows from the table.
create table Emp
(
recordNo int,
empID int,
eName varchar(10),
eSurname varchar(10),
age int,
sex char(1),
job varchar(15),
hiredate date,
salary number(8,2),
deptNo number(3,0),
mobNo int
);
Inserting the values into Emp table
insert into Emp
values ( 1,101,'Sanjay','Dayal',20,'M','Programmer',to_date('05-12-2016','dd-mmyyyy'),30000,10,889805);
insert into Emp
values ( 2,102,'Shahid','Pathan',22,'M','Operator',to_date('10-12-2016','dd-mmyyyy'),20000,20,999805);
insert into Emp
values ( 3,103,'Priya','Vyas',20,'F','Secretary',to_date('16-12-2016','dd-mmyyyy'),15000,10,999111);
insert into Emp
values ( 4,104,'Ajay','Dholpuriya',23,'M','Manager',to_date('01-12-2016','dd-mmyyyy'),35000,20,454890);
insert into Emp
values ( 5,105,'Riya','Sen',25,'F','DBA',to_date('20-12-2016','dd-mmyyyy'),70000,10,909123);
insert into Emp
values ( 6,111,'Shubham','Kushwah',30,'M','CEO',to_date('12-11-2016','dd-mmyyyy'),100000,20,555123);
insert into Emp
values ( 7,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 9,170,'Kajal','Gupta',25,'F','Receptionist',to_date('27-12-2016','dd-mmyyyy'),10000,20,555626);
select *from Emp
Alternative records (even no)
select recordno, empid, ename, esurname, sex, job, hiredate, salary from
(select recordno, empid, ename, esurname, sex, job, hiredate, salary, row_number() over
(order by recordno) as rownumber from emp)
where mod (rownumber,2)=0;
Alternative records (odd no)
select recordno, empid, ename, esurname, sex, job, hiredate, salary from
(select recordno, empid, ename, esurname, sex, job, hiredate, salary, row_number() over
(order by recordno) as rownumber from emp)
where mod (rownumber,2)<>0;
Experiment 4
Aim To find the third highest paid and the third lowest paid salary.
create table Emp
(
recordNo int,
empID int,
eName varchar(10),
eSurname varchar(10),
age int,
sex char(1),
job varchar(15),
hiredate date,
salary number(8,2),
deptNo number(3,0),
mobNo int
);
Inserting the values into Emp table
insert into Emp
values ( 1,101,'Sanjay','Dayal',20,'M','Programmer',to_date('05-12-2016','dd-mmyyyy'),30000,10,889805);
insert into Emp
values ( 2,102,'Shahid','Pathan',22,'M','Operator',to_date('10-12-2016','dd-mmyyyy'),20000,20,999805);
insert into Emp
values ( 3,103,'Priya','Vyas',20,'F','Secretary',to_date('16-12-2016','dd-mmyyyy'),15000,10,999111);
insert into Emp
values ( 4,104,'Ajay','Dholpuriya',23,'M','Manager',to_date('01-12-2016','dd-mmyyyy'),35000,20,454890);
insert into Emp
values ( 5,105,'Riya','Sen',25,'F','DBA',to_date('20-12-2016','dd-mmyyyy'),70000,10,909123);
insert into Emp
values ( 6,111,'Shubham','Kushwah',30,'M','CEO',to_date('12-11-2016','dd-mmyyyy'),100000,20,555123);
insert into Emp
values ( 7,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 9,170,'Kajal','Gupta',25,'F','Receptionist',to_date('27-12-2016','dd-mmyyyy'),10000,20,555626);
select *from Emp
Third highest paid salary
select empid, ename, esurname, sex, job, hiredate, salary from
(select empid, ename, esurname, sex, job, hiredate, salary, row_number() over (order by
salary desc) as rownumber from emp)
where rownumber=3;
Third lowest paid salary
select empid, ename, esurname, sex, job, hiredate, salary from
(select empid, ename, esurname, sex, job, hiredate, salary, row_number() over (order by
salary) as rownumber from emp)
where rownumber=3;
Experiment 5
Aim To display the 3rd, 4th and 6th rows from the table.
create table Emp
(
recordNo int,
empID int,
eName varchar(10),
eSurname varchar(10),
age int,
sex char(1),
job varchar(15),
hiredate date,
salary number(8,2),
deptNo number(3,0),
mobNo int
);
Inserting the values into Emp table
insert into Emp
values ( 1,101,'Sanjay','Dayal',20,'M','Programmer',to_date('05-12-2016','dd-mmyyyy'),30000,10,889805);
insert into Emp
values ( 2,102,'Shahid','Pathan',22,'M','Operator',to_date('10-12-2016','dd-mmyyyy'),20000,20,999805);
insert into Emp
values ( 3,103,'Priya','Vyas',20,'F','Secretary',to_date('16-12-2016','dd-mmyyyy'),15000,10,999111);
insert into Emp
values ( 4,104,'Ajay','Dholpuriya',23,'M','Manager',to_date('01-12-2016','dd-mmyyyy'),35000,20,454890);
insert into Emp
values ( 5,105,'Riya','Sen',25,'F','DBA',to_date('20-12-2016','dd-mmyyyy'),70000,10,909123);
insert into Emp
values ( 6,111,'Shubham','Kushwah',30,'M','CEO',to_date('12-11-2016','dd-mmyyyy'),100000,20,555123);
insert into Emp
values ( 7,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 9,170,'Kajal','Gupta',25,'F','Receptionist',to_date('27-12-2016','dd-mmyyyy'),10000,20,555626);
select *from Emp
Displaying 3rd,4th and 6th rows from the table Emp
select recordno, empid, ename, esurname, sex, job, hiredate, salary from
(select recordno, empid, ename, esurname, sex, job, hiredate, salary, row_number() over
(order by recordno) as rownumber from emp)
where rownumber in (3,4,6);
Experiment 6
Aim To display the employees name , which start with R and S.
create table Emp
(
recordNo int,
empID int,
eName varchar(10),
eSurname varchar(10),
age int,
sex char(1),
job varchar(15),
hiredate date,
salary number(8,2),
deptNo number(3,0),
mobNo int
);
Inserting the values into Emp table
insert into Emp
values ( 1,101,'Sanjay','Dayal',20,'M','Programmer',to_date('05-12-2016','dd-mmyyyy'),30000,10,889805);
insert into Emp
values ( 2,102,'Shahid','Pathan',22,'M','Operator',to_date('10-12-2016','dd-mmyyyy'),20000,20,999805);
insert into Emp
values ( 3,103,'Priya','Vyas',20,'F','Secretary',to_date('16-12-2016','dd-mmyyyy'),15000,10,999111);
insert into Emp
values ( 4,104,'Ajay','Dholpuriya',23,'M','Manager',to_date('01-12-2016','dd-mmyyyy'),35000,20,454890);
insert into Emp
values ( 5,105,'Riya','Sen',25,'F','DBA',to_date('20-12-2016','dd-mmyyyy'),70000,10,909123);
insert into Emp
values ( 6,111,'Shubham','Kushwah',30,'M','CEO',to_date('12-11-2016','dd-mmyyyy'),100000,20,555123);
insert into Emp
values ( 7,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 9,170,'Kajal','Gupta',25,'F','Receptionist',to_date('27-12-2016','dd-mmyyyy'),10000,20,555626);
select *from Emp
Displaying the employees name which start with R and S.
select eName from Emp
where eName LIKE 'R%' OR eName LIKE 'S%'
order by eName
Experiment 7
Aim Updating the multiple rows in using single update statement.
create table Emp
(
recordNo int,
empID int,
eName varchar(10),
eSurname varchar(10),
age int,
sex char(1),
job varchar(15),
hiredate date,
salary number(8,2),
deptNo number(3,0),
mobNo int
);
Inserting the values into Emp table
insert into Emp
values ( 1,101,'Sanjay','Dayal',20,'M','Programmer',to_date('05-12-2016','dd-mmyyyy'),30000,10,889805);
insert into Emp
values ( 2,102,'Shahid','Pathan',22,'M','Operator',to_date('10-12-2016','dd-mmyyyy'),20000,20,999805);
insert into Emp
values ( 3,103,'Priya','Vyas',20,'F','Secretary',to_date('16-12-2016','dd-mmyyyy'),15000,10,999111);
insert into Emp
values ( 4,104,'Ajay','Dholpuriya',23,'M','Manager',to_date('01-12-2016','dd-mmyyyy'),35000,20,454890);
insert into Emp
values ( 5,105,'Riya','Sen',25,'F','DBA',to_date('20-12-2016','dd-mmyyyy'),70000,10,909123);
insert into Emp
values ( 6,111,'Shubham','Kushwah',30,'M','CEO',to_date('12-11-2016','dd-mmyyyy'),100000,20,555123);
insert into Emp
values ( 7,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 9,170,'Kajal','Gupta',25,'F','Receptionist',to_date('27-12-2016','dd-mmyyyy'),10000,20,555626);
select *from Emp
Updating multiple rows using single update statement.
update Emp
set age = 21
where age = 20;
select *from Emp
Experiment 8
Aim To display the employees who were hired during the first half of the month.
create table Emp
(
recordNo int,
empID int,
eName varchar(10),
eSurname varchar(10),
age int,
sex char(1),
job varchar(15),
hiredate date,
salary number(8,2),
deptNo number(3,0),
mobNo int
);
Inserting the values into Emp table
insert into Emp
values ( 1,101,'Sanjay','Dayal',20,'M','Programmer',to_date('05-12-2016','dd-mmyyyy'),30000,10,889805);
insert into Emp
values ( 2,102,'Shahid','Pathan',22,'M','Operator',to_date('10-12-2016','dd-mmyyyy'),20000,20,999805);
insert into Emp
values ( 3,103,'Priya','Vyas',20,'F','Secretary',to_date('16-12-2016','dd-mmyyyy'),15000,10,999111);
insert into Emp
values ( 4,104,'Ajay','Dholpuriya',23,'M','Manager',to_date('01-12-2016','dd-mmyyyy'),35000,20,454890);
insert into Emp
values ( 5,105,'Riya','Sen',25,'F','DBA',to_date('20-12-2016','dd-mmyyyy'),70000,10,909123);
insert into Emp
values ( 6,111,'Shubham','Kushwah',30,'M','CEO',to_date('12-11-2016','dd-mmyyyy'),100000,20,555123);
insert into Emp
values ( 7,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 9,170,'Kajal','Gupta',25,'F','Receptionist',to_date('27-12-2016','dd-mmyyyy'),10000,20,555626);
select *from Emp
Displaying the employees who were hired during the first half of the month
select * from emp where hiredate between '01-dec-2016' and '15-dec-2016
Experiment 9
Aim To display Employee name , job and salary column from the table.
create table Emp
(
recordNo int,
empID int,
eName varchar(10),
eSurname varchar(10),
age int,
sex char(1),
job varchar(15),
hiredate date,
salary number(8,2),
deptNo number(3,0),
mobNo int
);
Inserting the values into Emp table
insert into Emp
values ( 1,101,'Sanjay','Dayal',20,'M','Programmer',to_date('05-12-2016','dd-mmyyyy'),30000,10,889805);
insert into Emp
values ( 2,102,'Shahid','Pathan',22,'M','Operator',to_date('10-12-2016','dd-mmyyyy'),20000,20,999805);
insert into Emp
values ( 3,103,'Priya','Vyas',20,'F','Secretary',to_date('16-12-2016','dd-mmyyyy'),15000,10,999111);
insert into Emp
values ( 4,104,'Ajay','Dholpuriya',23,'M','Manager',to_date('01-12-2016','dd-mmyyyy'),35000,20,454890);
insert into Emp
values ( 5,105,'Riya','Sen',25,'F','DBA',to_date('20-12-2016','dd-mmyyyy'),70000,10,909123);
insert into Emp
values ( 6,111,'Shubham','Kushwah',30,'M','CEO',to_date('12-11-2016','dd-mmyyyy'),100000,20,555123);
insert into Emp
values ( 7,110,'Rishabh','Gupta',23,'M','HR',to_date('23-12-2016','dd-mmyyyy'),25000,40,787956);
insert into Emp
values ( 9,170,'Kajal','Gupta',25,'F','Receptionist',to_date('27-12-2016','dd-mmyyyy'),10000,20,555626);
select *from Emp
Displaying Employee name , job and salary column from the table Emp
select eName, job , salary from Emp
Experiment 10
Aim To Study the E-R diagram.
E-R Diagram
ER-Diagram is a visual representation of data that describes how data is related to each other.
The ER model defines the conceptual view of a database. It works around real-world entities and
the associations among them. At view level, the ER model is considered a good option for
designing databases.
An entity-relationship diagram (ERD) is a graphical representation of an information system that
shows the relationship between people, objects, places, concepts or events within that system. An
ERD is a data modeling technique that can help define business processes and can be used as the
foundation for a relational database.
Symbols and Notations
Components of E-R Diagram
The E-R diagram has three main components.
1) Entity
An Entity can be any object, place, person or class. In E-R Diagram, an entity is represented
using rectangles. Consider an example of an Organisation. Employee, Manager, Department,
Product and many more can be taken as entities from an Organisation.
Weak Entity
Weak entity is an entity that depends on another entity. Weak entity doesn't have key attribute of
their own. Double rectangle represents weak entity.
2) Attribute
An Attribute describes a property or characteristics of an entity. For example, Name, Age,
Address etc can be attributes of a Student. An attribute is represented using eclipse.
Key Attribute
Key attribute represents the main characteristics of an Entity. It is used to represent Primary key.
Ellipses with underlying lines represent Key Attribute.
Composite Attribute
An attribute can also have its own attributes. These attributes are known as Composite attribute.
3) Relationship
A Relationship describes relations between entities. Relationship is represented using diamonds.
There are three types of relationship that exist between Entities.
Binary Relationship
Recursive Relationship
Ternary Relationship
Binary Relationship
Binary Relationship means relation between two Entities. This is further divided into three types.
1. One to One : This type of relationship is rarely seen in real world.
The above example describes that one student can enroll only for one course and a course
will also have only one Student. This is not what you will usually see in relationship.
2. One to Many : It reflects business rule that one entity is associated with many number of same
entity. The example for this relation might sound a little weird, but this menas that one student
can enroll to many courses, but one course will have one Student.
The arrows in the diagram describes that one student can enroll for only one course.
3. Many to One : It reflects business rule that many entities can be associated with just one entity.
For example, Student enrolls for only one Course but a Course can have many Students.
4. Many to Many :
The above diagram represents that many students can enroll for more than one courses.
Recursive Relationship
When an Entity is related with itself it is known as Recursive Relationship.
Ternary Relationship
Relationship of degree three is called Ternary relationship.
Experiment 10
Aim To desing an E-R diagram for hospital management system.