You are on page 1of 20

DR.

VIRENDRA SWARUP INSTITUTE OF COMPUTER STUDIES

PRACTICAL FILE
ON
DATABASE MANAGEMENT SYSTEM (BCA-4002 P)
SESSION: BCA 2022 IV SEMESTER SECTION-A (2023 -24)

SUBMITTED IN
PARTIAL FULFILLMENT FOR AWARD OF THE DEGREE OF
BACHELOR OF COMPUTER APPLICATION
CHHATRAPATI SHAHU JI MAHARAJ UNIVERSITY, KANPUR, UP

SUBMITTED TO: SUBMITTED BY:


Mr.RAM AWTAR STUDENT NAME
FACULTY BCA 2022 4 SEM
ACKNOWLEDGEMENT

I would like to express my sincere thanks of gratitude to my


respected faculty MR. RAM AWTAR
who guided me to complete the following practical file.

I would also like to pay thanks


to my Head Academics, Head of Department and Lab In charge for their
support.

STUDENT SIGNATURE

STUDENT NAME
INDEX (DATABASE MANAGEMENT SYSTEM)

S NO. TOPIC PAGE REMARKS.


NO.
1 Notations Of ER Model
2 Entity Relationship Model Of
Company Database
3 Relational Model Of Company
3a Depiction of Primary keys

3b Depiction Foreign or Referential


keys

3c Populated Database

4 Creation of scripts, insertion and


updation of records
4a Creation of tables

4b Insertion of records
4c Updating On Records
5 Queries testing on Populated
Database of Company
1.Notations of ER Model:
2.Ent
ity

Relationship Model of Company Database

3.Relational Model Of Company


a.Depiction of Primary keys

b. Depiction Foreign or Referential keys


c. Populated Database
EMPLOYEE:

DEPARTMENT: WORKS_ON:

PROJECT:

DEPENDENT: DEPT_LOCATIONS:

4.Creation of scripts, insertion and updation


of records
a). Creation of tables
create table employee(Fname varchar2(15) not null,
Minit varchar2(1) not null,
Lname varchar2(15) not null,
Ssn number(10) not null,
Bdate date not null,
Address varchar2(20) not null,
Sex varchar2(1) not null,
Salary number(5) not null,
Super_ssn number(10),
primary key(ssn),
foreign key(Super_ssn) references employee(Ssn));

create table department


(Dname varchar2(10) not null,
Dnumber number(2) primary key,
Mgr_ssn number(10),
Mgr_start_date date not null,
foreign key(Mgr_ssn) references employee(Ssn));

alter table employee


add (Dno)number(2)
foreign key (Dno) references Department(Dnumber));

create table dept_locations


(Dnumber number(2) references department(Dnumber),
Dlocation varchar2(15),
primary key (Dnumber,Dlocation));

create table project


(Pname varchar2(15) not null,
Pnumber number(2) primary key,
Plocation varchar2(15) not null,
Dnum number(2) references department(Dnumber));

create table works_on


(Essn number(10),
Pno number(2) references project(Pnumber),
hours number(3,1),
primary key(Essn,Pno),
foreign key(Essn) references employee(ssn));

create table dependent


(Essn number(10),
Dependent_name varchar2(10),
sex varchar2(1) not null,
Bdate date not null,
Releationship varchar2(10) not null,
primary key(Essn,Dependent_name),
foreign key(Essn) references employee(Ssn));

b). Insertion of records


1.In Employee Table:
insert intoemployee(Fname,minit,lname,ssn,bdate,address,sex,salary)
values('John','B','Smith',123456789,to_date('1965-01-09','yyyy-mm-dd'),'731
Fondren, Mouston, TX','M',30000)

insert into employee(Fname,minit,lname,ssn,bdate,address,sex,salary)


values('Franklin','T','Wonk',333445555,to_date('1955-12-08','yyyy-mm-
dd'),'638 Vost,Houston,TX','M',40000)

insert into employee(Fname,minit,lname,ssn,bdate,address,sex,salary,super_ssn)


values('Alicia','','Wallace',987654321,to_date('1941-06-20','yyyy-mm-dd'),'291
Castle, Spring, TX','F',25000,333445555)

insert into employee(Fname,minit,lname,ssn,bdate,address,sex,salary)


values('Zennifer','S','Wallace',987654321,to_date('1941-06-20','yyyy-mm-
dd'),'291 Berry, Bollare, TX','F',43000)

insert into employee(Fname,minit,lname,ssn,bdate,address,sex,salary)


values('Ramesh','K','Narayan',666884444,to_date('1962-09-15','yyyy-mm-
dd'),'975 Fire Oak,Humble, TX','M',38000)

insert into employee(Fname,minit,lname,ssn,bdate,address,sex,salary)


values('Ahmad','v','Jabbar',987987987,to_date('1969-03-29','yyyy-mm-dd'),'980
Dallas,Houstion, TX','M',25000)

insert into employee(Fname,minit,lname,ssn,bdate,address,sex,salary)


values('James','E','Borg',888665555,to_date('1937-11-10','yyyy-mm-dd'),'450
Stone,Houstion, TX','M',55000)
insert into employee(Fname,minit,lname,ssn,bdate,address,sex,salary)
values('Joyce','A','English',453453453,to_date('1972-07-31','yyyy-mm-
dd'),'5631 Rice,Houstion, TX','F',25000)
2.In Department Table:
insert into Department
values('Research',5,333445555,to_date('1988-05-22','yyyy-mm-dd'));

insert into Department


values('Administration',4,987654321,to_date('1995-01-01','yyyy-
mm-dd'));

insert into Department


values('Headquarters',1,888665555,to_date('1981-06-19','yyyy-mm-dd'));

3.In Dept_location Table:


insert into dept_locations values(1,'Houston');
insert into dept_locations values(4,'Stafford');
insert into dept_locations values(5,'Bellarre');
insert into dept_locations values(5,'Sugarland');
insert into dept_locations values(5,'Houston');

4.In Project Table:


insert into project values('ProductsX',1,'Bellaire',5);
insert into project values('ProductsY',2,'Sugarland',5);
insert into project values('ProductsZ',3,'Houston',5);
insert into project values('Computerization',10,'Stafford',4);
insert into project values('Reorganization',20,'Houston',1);
insert into project values('Newbenefits',30,'Stafford',4);

5.In Works_on Table:


insert into works_on values(123456789,1,3.2);
insert into works_on values(123456789,2,7.5);
insert into works_on values(666884444,3,40.0);
insert into works_on values(453453453,1,20.0);
insert into works_on values(453453453,2,20.0);
insert into works_on values(333445555,2,10.0);
insert into works_on values(333445555,3,10.0);
insert into works_on values(333445555,10,10.0);
insert into works_on values(333445555,20,10.0);
insert into works_on values(999887777,30,30.0);
insert into works_on values(999887777,10,10.0);
insert into works_on values(987987987,10,35.0);
insert into works_on values(987987987,30,5.0);
insert into works_on values(987654321,30,20.0);
insert into works_on values(987654321,20,75.0);
insert into works_on values(888665555,20,null);

6.In Dependent Table:


insert into dependent values(333445555,'Alice','F',TO_DATE('1986-04-
05','yyyy-mm-dd'),'daughter');

insert into dependent values(333445555,'Theodore','M',TO_DATE('1983-10-


25','yyyy-mm-dd'),'son');

insert into dependent values(333445555,'Joy','F',TO_DATE('1958-05-03','yyyy-


mm-dd'),'spouse');

insert into dependent values(987654321,'Abner','M',TO_DATE('1942-02-


28','yyyy-mm-dd'),'spouse');

insert into dependent values(123456789,'Michael','M',TO_DATE('1988-01-


04','yyyy-mm-dd'),'son');

insert into dependent values(123456789,'Alice','F',TO_DATE('1988-12-


30','yyyy-mm-dd'),'daughter');

insert into dependent values(123456789,'Elizabeth','F',TO_DATE('1967-05-


05','yyyy-mm-dd'),'spouse');

c). Updating On Records


update employee
set super_ssn=333445555
where super_ssn is null and minit='B';

update employee
set super_ssn=888565555
where ssn=333445555;

update employee
set super_ssn=333445555
where ssn=999887777;

update employee
set super_ssn=987654321
where ssn=999887777;

update employee
set super_ssn=888665555
where ssn=987654321;

update employee
set super_ssn=333445555
where ssn=666884444;

update employee
set super_ssn=333445555
where ssn=453453453;

update employee
set super_ssn=987654321
where ssn=987987987;

update employee
set super_ssn=null
where ssn=888665555;
Alter table employee add(Dno number(1));

update employee
set Dno=5
where minit='B';
update employee
set Dno=5
where minit='T';

update employee
set Dno=4
where minit='J';

update employee
set Dno=4
where minit='S';

update employee
set Dno=5
where minit='K';

update employee
set Dno=5
where minit='A';

update employee
set Dno=4
where minit='V';

update employee
set Dno=1
where minit='E';

5.Query testing on Populated Database


Query 1: Retrieve the birth date and address of the employee whose name is 'John B. Smith'.
Q1: SELECT BDATE, ADDRESS FROM EMPLOYEE WHERE FNAME='John' AND MINIT='B'
AND LNAME='Smith'
Query 2: Retrieve the name and address of all employees who work for the 'Research' department.
Q2:SELECT FNAME, LNAME, ADDRESS FROM(EMPLOYEE JOIN DEPARTMENT ON
DNUMBER=DNO )
WHERE DNAME='Research'

Query 3: For every project located in 'Stafford', list the project number, the controlling department
number, and the department manager's last name, address, and birthdate.
Q3: SELECT PNUMBER,DNUM,LNAME,BDATE,ADDRESS FROM
PROJECT,DEPARTMENT,EMPLOYEE WHERE DNUM=DNUMBER AND MGR_SSN=SSN
AND PLOCATION='Stafford'

Query 4: Make a list of all project numbers for projects that involve an employee whose last name is
'Smith' as a worker or as a manager of the department that controls the project.
Q4:SELECT PNAME FROM PROJECT,DEPARTMENT,EMPLOYEE WHERE
DNUM=DNUMBER AND MGR_SSN=SSN AND LNAME='Smith'
UNION (SELECT PNAME FROM PROJECT, WORKS_ON, EMPLOYEE WHERE
PNUMBER=PNO AND ESSN=SSN AND LNAME='Smith')

Query 5: Retrieve the names of employees who have no dependents.


Q5:SELECT FNAME, LNAME FROM EMPLOYEE WHERE NOT EXISTS (SELECT * FROM
DEPENDENT WHERE SSN=ESSN)
Query 6: For each employee, retrieve the employee's name, and the name of his or her immediate
supervisor.
Q6:SELECT E.FNAME, E.LNAME,S.FNAME,S.LNAME FROM EMPLOYEE E,EMPLOYEE S
WHERE E.SUPER_SSN=S.SSN

Query 7: Retrieve the SSN values for all employees.


Q7:SELECT SSN FROM EMPLOYEE

Query 8:Retrieve the SSN values and Department Name for all employees.
Q8:SELECT SSN, DNAME FROM EMPLOYEE, DEPARTMENT
Query 9:Retrieve the different SALARY values for all employees.
Q9 : SELECT DISTINCT SALARY FROM EMPLOYEE

Query 10: Retrieve the names of all employees who do not have supervisors.
Q10:SELECT FNAME, LNAME FROM EMPLOYEE WHERE SUPER_SSN IS NULL

Query 11: Retrieve the name of each employee who has a dependent with the same first name as the
employee.
Q11: SELECT E.FNAME, E.LNAME FROM EMPLOYEE E WHERE E.SSN IN (SELECT ESSN
FROM DEPENDENT WHERE ESSN=E.SSN AND E.FNAME=DEPENDENT_NAME)

Query 12: Retrieve the social security numbers of all employees who work on project number 1, 2,
or 3.
Q12:SELECT DISTINCT ESSN FROM WORKS_ON WHERE PNO IN (1, 2, 3)

Query 13: Find the maximum salary, the minimum salary, and the average salary among all
employees.
Q13:SELECT MAX(SALARY), MIN(SALARY), AVG(SALARY) FROM EMPLOYEE

Query 14: Find the maximum salary, the minimum salary, and the average salary among employees
who work for the 'Research' department.
Q14: SELECT MAX(SALARY), MIN(SALARY), AVG(SALARY) FROM EMPLOYEE,
DEPARTMENT WHERE DNO=DNUMBER AND DNAME='Research'

Queries 15: Retrieve the total number of employees in the company


Q15: SELECT COUNT (*) FROM EMPLOYEE

Queries 16: Retrieve the number of employees in the 'Research' department


Q16: SELECT COUNT (*) FROM EMPLOYEE,DEPARTMENT WHERE DNO=DNUMBER
AND DNAME=’Research’
Query 17: For each department, retrieve the department number, the number of employees in the
department, and their average salary.
Q17: SELECT DNO, COUNT (*), AVG (SALARY)FROM EMPLOYEE GROUP BY
DNO

Query 18: For each project, retrieve the project number, project name, and the number of employees
who work on that project.
Q18: SELECT PNUMBER, PNAME, COUNT (*) FROM PROJECT, WORKS_ON
WHERE PNUMBER=PNO GROUP BY PNUMBER, PNAME

Query 19: For each project on which more than two employees work , retrieve the project number,
project name, and the number of employees who work on that project.
Q19: SELECT PNUMBER, PNAME, COUNT (*) FROM PROJECT, WORKS_ON
WHERE PNUMBER=PNO GROUP BY PNUMBER, PNAME HAVING COUNT (*) > 2

Query 20: Retrieve all employees whose address is in Houston, Texas. Here, the value of the
ADDRESS attribute must contain the substring 'HoustonTX'.
Q20: SELECT FNAME, LNAME FROM EMPLOYEE WHERE ADDRESS LIKE '%HoustonTX
%'
Query 21: Retrieve all employees who were born during the 1950s. Here, '5' must be the 9th character
of the string (according to our format for date), so the BDATE value is '________5_', with each
underscore as a place holder for a single arbitrary character.
Q21: SELECT FNAME, LNAME FROM EMPLOYEE WHERE BDATE LIKE '________5_'

Query 22: Show the effect of giving all employees who work on the 'ProductX' project a 10% raise.
Q22:SELECT FNAME, LNAME, 1.1*SALARY FROM EMPLOYEE, WORKS_ON, PROJECT
WHERE SSN=ESSN AND PNO=PNUMBER AND PNAME='ProductX'

Query 23: Retrieve a list of employees and the projects each works in, ordered by the employee's
department, and within each department ordered alphabetically by employee last name.
Q23: SELECT DNAME, LNAME, FNAME, PNAME FROM DEPARTMENT,
EMPLOYEE,WORKS_ON, PROJECT WHERE DNUMBER=DNO AND SSN=ESSN AND
PNO=PNUMBER ORDER BY DNAME, LNAME

You might also like