0% found this document useful (0 votes)
711 views

03 Employee Database

The document describes an experiment involving the creation of tables for a company database with information on employees, departments, projects, and employee assignments. It includes the schema for the tables, instructions on creating the tables, inserting sample data, and performing updates. The goals are to write SQL queries to retrieve specified information from the tables, such as projects involving an employee, effects of salary increases, department salary details, and employee assignments.

Uploaded by

Game Master
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
711 views

03 Employee Database

The document describes an experiment involving the creation of tables for a company database with information on employees, departments, projects, and employee assignments. It includes the schema for the tables, instructions on creating the tables, inserting sample data, and performing updates. The goals are to write SQL queries to retrieve specified information from the tables, such as projects involving an employee, effects of salary increases, department salary details, and employee assignments.

Uploaded by

Game Master
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

17CSL58: DBMS LABORATOTY WITH MINI PROJECT

EXPERIMENT No. 05: Company Database


5.1 Experiment Details 5.5 Results
5.2 Softwares Required 5.6 Pre-Experiment Questions
5.3 Pre-Requisite 5.7 Post-Experiment Questions
5.4 Procedure

5.1 Experiment Details:


Consider the schema for Company Database:
EMPLOYEE (SSN, Name, Address, Sex, Salary, SuperSSN, DNo)
DEPARTMENT (DNo, DName, MgrSSN, MgrStartDate)
DLOCATION (DNo,DLoc)
PROJECT (PNo, PName, PLocation, DNo)
WORKS_ON (SSN, PNo, Hours)
Write SQL queries to
1. Make a list of all project numbers for projects that involve an employee whose name
is ‘Scott’, either as a worker or as a manager of the department that controls the
project.
2. Show the resulting salaries if every employee working on the ‘IoT’ project is given a
10 percent raise.
3. Find the sum of the salaries of all employees of the ‘Accounts’ department, as well
as the maximum salary, the minimum salary, and the average salary in this
department
4. Retrieve the name of each employee who works on all the projects controlled by
department number 5 (use NOT EXISTS operator).
5. For each department that has more than five employees, retrieve the department
number and the number of its employees who are making more than Rs. 6, 00,000.
5.2 Softwares Required:
Operating System: Windows 7
DBMS: Oracle 10g

5.3 Pre-Requisite:
Basics of DBMS, SQL Programming

Department of Information Science & Engineering, SCEM, Mangaluru. 51


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

5.4 Procedure:
TABLE CREATION:

CREATE TABLE DEPARTMENT (


DNO INT,
DNAME VARCHAR (30),
MGR_SSN VARCHAR (10),
MGR_START_DATE DATE,
PRIMARY KEY (DNO));

CREATE TABLE EMPLOYEE (


SSN VARCHAR (10),
NAME VARCHAR (20),
ADDRESS VARCHAR (20),
SEX CHAR (1),
SALARY DECIMAL (10, 3),
SUPER_SSN VARCHAR (10),
DNO INT,
PRIMARY KEY (SSN),
FOREIGN KEY (SUPER_SSN) REFERENCES EMPLOYEE (SSN)
ON DELETE CASCADE,
FOREIGN KEY (DNO) REFERENCES DEPARTMENT (DNO)
ON DELETE CASCADE);

CREATE TABLE DLOCATION (


DNO INT,
DLOC VARCHAR (20),
PRIMARY KEY (DNO, DLOC),
FOREIGN KEY (DNO) REFERENCES DEPARTMENT (DNO)
ON DELETE CASCADE);

Department of Information Science & Engineering, SCEM, Mangaluru. 52


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

CREATE TABLE PROJECT (


PNO INT,
PNAME VARCHAR (20),
PLOCATION VARCHAR (20),
DNO INT,
PRIMARY KEY (PNO),
FOREIGN KEY (DNO) REFERENCES DEPARTMENT (DNO)
ON DELETE CASCADE);

CREATE TABLE WORKS_ON (


SSN VARCHAR (20),
PNO INT,
HOURS INT,
PRIMARY KEY (SSN, PNO),
FOREIGN KEY (SSN) REFERENCES EMPLOYEE (SSN)
ON DELETE CASCADE,
FOREIGN KEY (PNO) REFERENCES PROJECT (PNO)
ON DELETE CASCADE);

SQL> ALTER TABLE DEPARTMENT


ADD CONSTRAINT C_MSSN
FOREIGN KEY (MGR_SSN) REFERENCES EMPLOYEE
ON DELETE CASCADE;

Table altered.

Department of Information Science & Engineering, SCEM, Mangaluru. 53


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

INSERTION OF VALUES:

SQL> INSERT INTO DEPARTMENT VALUES


('&DNO','&DNAME','&MGRSSN','&MGRSTARTDATE');
Enter value for dno: 1
Enter value for dname: ACCOUNTS
Enter value for mgrssn:
Enter value for mgrstartdate: 25-MAR-2018
Old 1: INSERT INTO DEPARTMENT VALUES
('&DNO','&DNAME','&MGRSSN','&MGRSTARTDATE')
New 1: INSERT INTO DEPARTMENT VALUES ('1','ACCOUNTS','','25-MAR-2018')

SQL> SELECT * FROM DEPARTMENT;

DNO DNAME MGR_SSN MGR_START


------- --------------------------- ---------- ---------
1 ACCOUNTS 25-MAR-18
2 DEVELOPER 25-JUL-17
3 ESTABLISHMENT 16-DEC-15
4 FINANCE 08-JAN-11
5 MAMNAGEMENT 11-NOV-09

SQL> INSERT INTO EMPLOYEE VALUES


('&SSN','&NAME','&ADDRESS','&SEX','&SALARY','&SUPERSSN','&DNO');
Enter value for ssn: E1
Enter value for name: SCOTT
Enter value for address: SAN FRANSISCO
Enter value for sex: M
Enter value for salary: 700000
Enter value for superssn:
Enter value for dno: 1

Department of Information Science & Engineering, SCEM, Mangaluru. 54


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

Old 1: INSERT INTO EMPLOYEE VALUES


('&SSN','&NAME','&ADDRESS','&SEX','&SALARY','&SUPERSSN','&DNO')
New 1: INSERT INTO EMPLOYEE VALUES
('E1','SCOTT','SAN FRANSISCO','M','700000','','1')

SQL> SELECT * FROM EMPLOYEE;

SSN NAME ADDRESS SEX SALARY SUPER_SSN DNO


------ ---------------- ---------------------- ------- ---------- --------------- -------
E1 SCOTT SAN FRANSISCO M 700000 1
E2 ALBERT SAN ANDREAS M 800000 E1 1
E3 JULIET ENGLAND F 900000 E2 1
E4 ROBERT NEW YORK M 850000 E1 1
E5 BAIRSTOW NEW ZEALAND M 750000 E4 1
E6 SMITH AUSTRALIA M 800000 E4 1
E7 WARNER TURKEY M 500000 E3 2
E8 LUCY AFRICA F 400000 E6 3
E9 ROSE NETHERLANDS F 300000 E8 4
E10 ALIS NEIGERIA M 750000 E2 5
E11 JAMES CHINA M 900000 E8 5
E12 ANDERSON KOREA M 500000 E9 4
E13 DISHA MUMBAI F 400000 E12 3
E14 SARA DELHI F 250000 E14 4
E15 JOYCE CALIFORNIA M 60000 E13 5

SQL> UPDATE EMPLOYEE SET SUPER_SSN='E15' WHERE SSN='E1';

Department of Information Science & Engineering, SCEM, Mangaluru. 55


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

SQL> SELECT * FROM EMPLOYEE;

SSN NAME ADDRESS SEX SALARY SUPER_SSN DNO


------ ---------------- ---------------------- ------- ---------- --------------- -------
E1 SCOTT SAN FRANSISCO M 700000 E15 1
E2 ALBERT SAN ANDREAS M 800000 E1 1
E3 JULIET ENGLAND F 900000 E2 1
E4 ROBERT NEW YORK M 850000 E1 1
E5 BAIRSTOW NEW ZEALAND M 750000 E4 1
E6 SMITH AUSTRALIA M 800000 E4 1
E7 WARNER TURKEY M 500000 E3 2
E8 LUCY AFRICA F 400000 E6 3
E9 ROSE NETHERLANDS F 300000 E8 4
E10 ALIS NEIGERIA M 750000 E2 5
E11 JAMES CHINA M 900000 E8 5
E12 ANDERSON KOREA M 500000 E9 4
E13 DISHA MUMBAI F 400000 E12 3
E14 SARA DELHI F 250000 E14 4
E15 JOYCE CALIFORNIA M 60000 E13 5

SQL> UPDATE DEPARTMENT SET MGR_SSN='E4' WHERE DNO='1';

SQL> UPDATE DEPARTMENT SET MGR_SSN='E2' WHERE DNO='2';

SQL> UPDATE DEPARTMENT SET MGR_SSN='E1' WHERE DNO='3';

SQL> UPDATE DEPARTMENT SET MGR_SSN='E5' WHERE DNO='4';


.
SQL> UPDATE DEPARTMENT SET MGR_SSN='E3' WHERE DNO='5';

Department of Information Science & Engineering, SCEM, Mangaluru. 56


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

SQL> SELECT * FROM DEPARTMENT;

DNO DNAME MGR_SSN MGR_START


------- ------------------------- ---------- ---------
1 ACCOUNTS E4 25-MAR-18
2 DEVELOPER E2 25-JUL-17
3 ESTABLISHMENT E1 16-DEC-15
4 FINANCE E5 08-JAN-11
5 MAMNAGEMENT E3 11-NOV-09

SQL> INSERT INTO DLOCATION VALUES ('&DNO','&DLOC');


Enter value for dno: 1
Enter value for dloc: RUSSIA
Old 1: INSERT INTO DLOCATION VALUES ('&DNO','&DLOC')
New 1: INSERT INTO DLOCATION VALUES ('1','RUSSIA')

SQL> SELECT * FROM DLOCATION;

DNO DLOC
---------- --------------------
1 RUSSIA
2 CHINA
3 LOS VEGAS
4 MUMBAI
5 CALIFORNIA

SQL> INSERT INTO PROJECT VALUES


('&PNO','&PNAME','&PLOACTION','&DNO');
Enter value for pno: 1
Enter value for pname: IOT
Enter value for ploaction: MUMBAI
Enter value for dno: 1

Department of Information Science & Engineering, SCEM, Mangaluru. 57


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

Old 1: INSERT INTO PROJECT VALUES


('&PNO','&PNAME','&PLOACTION','&DNO')
New 1: INSERT INTO PROJECT VALUES ('1','IOT','MUMBAI','1')

SQL> SELECT * FROM PROJECT;

PNO PNAME PLOCATION DNO


------ -------------------------------- ------------------ -------
1 IOT MUMBAI 1
2 BANK SOFTWARE BANGALORE 2
3 EMBEDDED SYSTEMS HONG KONG 3
4 FOREST DEPARTMENT DELHI 4
5 GOVERNMENT APP GANDHINAGAR 5

SQL> INSERT INTO WORKS_ON VALUES ('&SSN','&PNO','&HOURS');


Enter value for ssn: E1
Enter value for pno: 1
Enter value for hours: 8
Old 1: INSERT INTO WORKS_ON VALUES ('&SSN','&PNO','&HOURS')
New 1: INSERT INTO WORKS_ON VALUES ('E1','1','8')

SQL> SELECT * FROM WORKS_ON;

SSN PNO HOURS


------ ------- ----------
E1 1 8
E2 2 9
E3 3 6
E4 4 5
E5 5 10

Department of Information Science & Engineering, SCEM, Mangaluru. 58


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

5.5 RESULTS:

QUERY 1:

(SELECT DISTINCT P.PNO FROM PROJECT P, EMPLOYEE E, DEPARTMENT D


WHERE E.SSN=D.MGR_SSN AND D.DNO=P.DNO AND E.NAME='SCOTT')
UNION
(SELECT DISTINCT P.PNO FROM PROJECT P, EMPLOYEE E, WORKS_ON W
WHERE E.SSN=W.SSN AND P.PNO=W.PNO AND E.NAME='SCOTT');

PNO
-------
1
3

QUERY 2:

SELECT E.NAME, 1.1*SALARY AS INCREASED_SALARY FROM EMPLOYEE E,


PROJECT P, WORKS_ON W WHERE E.SSN=W.SSN AND P.PNO=W.PNO AND
P.PNAME='IOT';

NAME INCREASED_SALARY
--------- ----------------
SCOTT 770000

Department of Information Science & Engineering, SCEM, Mangaluru. 59


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

QUERY 3:

SELECT SUM (SALARY), MAX (SALARY), MIN (SALARY), AVG (SALARY) FROM
EMPLOYEE E, DEPARTMENT D WHERE
E.DNO=D.DNO AND D.DNAME='ACCOUNTS';

SUM (SALARY) MAX (SALARY) MIN (SALARY) AVG (SALARY)


----------- ----------- ----------- -----------
4800000 900000 700000 800000

QUERY 4:

SELECT E.NAME FROM EMPLOYEE E WHERE NOT EXISTS


((SELECT P.PNO FROM PROJECT P WHERE P.DNO=5)
MINUS
(SELECT W.PNO FROM WORKS_ON W WHERE E.SSN=W.SSN));

NAME
----------------
BAIRSTOW

QUERY 5:

SELECT E.DNO, COUNT (*) FROM EMPLOYEE E WHERE SALARY > 600000 AND
E.DNO IN
(SELECT DNO FROM EMPLOYEE GROUP BY DNO HAVING COUNT (*) > 5)
GROUP BY E.DNO;

DNO COUNT (*)


------- ----------
1 6

Department of Information Science & Engineering, SCEM, Mangaluru. 60


17CSL58: DBMS LABORATOTY WITH MINI PROJECT

5.6 Pre – Experiment Questions:

1. What is indexing and what are the different kinds of indexing?


2. What is system catalog or catalog relation? How is better known as?
3. What is meant by query optimization?
4. What is join dependency and inclusion dependency?

5.7 Post – Experiment Questions:

1. What is durability in DBMS?


2. What do you mean by atomicity and aggregation?
3. What is a checkpoint and when does it occur?
4. What are the different phases of transaction?
5. What is "transparent DBMS"?

Department of Information Science & Engineering, SCEM, Mangaluru. 61

You might also like