0% found this document useful (0 votes)
97 views13 pages

Data-Base: Punjab University College of Information Technology

This document contains 14 tasks related to querying and modifying data in database tables. The tasks include writing queries to retrieve data from multiple tables based on filters and joins, inserting a new record, updating existing records, and deleting records. The tasks use tables like EMP, DEPT, and SALGRADE to demonstrate basic operations on data in Oracle SQL.

Uploaded by

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

Data-Base: Punjab University College of Information Technology

This document contains 14 tasks related to querying and modifying data in database tables. The tasks include writing queries to retrieve data from multiple tables based on filters and joins, inserting a new record, updating existing records, and deleting records. The tasks use tables like EMP, DEPT, and SALGRADE to demonstrate basic operations on data in Oracle SQL.

Uploaded by

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

2020

PUNJAB UNIVERSITY COLLEGE OF INFORMATION


TECHNOLOGY
LAB09

DATA-BASE
Prepared for Miss. Hareem Aslam
By. Talha Mazhar Bitf19a024
TASK 1

Write a query that display the location of all employees and location of their managers.

SELECT E1.ename, D1.loc, E2.ename, D2.loc

FROM dept D1, emp E1, emp E2, dept D2

WHERE E1.deptno = D1.deptno

AND E2.deptno = D2.deptno

AND E2.empno = E1.mgr

TASK 2

Write a query that displays all the employees that have salary grade of 2 or they belong to ‘BOSTON’.

SELECT *

FROM emp e, salgrade s, dept d

WHERE e.sal BETWEEN s.losal AND s.hisal

AND
s.grade

IN

(2)

AND

d.loc = 'BOSTON';

TASK 3

Write a query that display the salary grades of all employees that belongs to Sales Department .

SELECT e.ename, s.grade

FROM emp e, dept d, salgrade s

WHERE (e.deptno = d.deptno

AND

d.dname = 'SALES')

AND

(e.sal BETWEEN losal AND hisal)

ORDER BY e.ename
TASK 4

Write a query that display the locations of all employees that earn more than ‘BLAKE’.

SELECT emp.ename, dept.loc

FROM emp, dept

WHERE emp.deptno = dept.deptno

AND

emp.sal >

(SELECT sal from emp

WHERE ename = 'BLAKE')


Task 5

DISPLAY THE EMPLOYEE NAME AND EMPLOYEE NUMBER ALONG WITH THEIR MANAGER’S NAME AND MANAGER NUMBER. LABEL
THE COLUMNS EMPLOYEE, EMP#, MANAGER, AND MGR#, RESPECTIVELY.

SELECT e.ename, e.empno, e1.ename, e1.mgr FROM emp e, emp e1

WHERE e.mgr = e1.empno;


TASK 6

CREATE A QUERY THAT DISPLAYS EMPLOYEE NAMES, DEPARTMENT NUMBERS, AND ALL THE DEPARTMENT NAME WHO WORK IN
THE DEPARTMENT 10. GIVE EACH COLUMN AN APPROPRIATE LABEL.

SELECT e.ename, d.deptno, d1.dname

FROM emp e, dept d, dept d1

WHERE d1.deptno = 10

AND

d.deptno = 10;
TASK 7

DISPLAY THE NAMES AND HIRE DATES FOR ALL EMPLOYEES WHO WERE HIRED BEFORE THEIR MANAGERS, ALONG WITH THEIR
MANAGER’S NAMES AND HIRE DATES. LABEL THE COLUMNS EMPLOYEE, EMP HIRED, MANAGER, AND MGR HIRED, RESPECTIVELY.

SELECT emp1.ename, emp1.hiredate, emp2.ename, emp2.hiredate

FROM emp emp1, emp emp2

WHERE emp1.mgr = emp2.empno

AND

emp1.hiredate < emp2.hiredate


TASK 8

INSERT A ROW IN EMPLOYEE TABLE WITH YOUR NAME AND YOUR ROLL NO DIGIT AS EMP NO AND OTHER FIELDS OF YOUR OWN
CHOICE.

INSERT INTO

emp

(empno, ename, job, mgr, hiredate, sal, comm, deptno)

VALUES

(520, 'TALHA', 'BOSS', 7649, '02-25-2002', 9000, 600, 70)


TASK 9

UPDATE YOUR NAME AS YOUR FATHER’S NAME AND SALARY TO 20000 IN EMPLOYEE TABLE WHICH YOU ADDED.

UPDATE emp

SET ename = 'MAZHAR', sal=40000

WHERE ename = 'TALHA'

AND

sal=6400;

TASK 10
UPDATE YOUR SALARY AND JOB AS THE SAL AND JOB OF KING.

UPDATE emp

SET (sal, job)=(SELECT sal, job FROM emp WHERE ename = 'BOSS')

WHERE ename = 'MAZHAR'

TASK 11

DELETE THE ROW IN EMPLOYEE TABLE WHICH YOU ADDED WITH YOUR NAME.

DELETE

FROM emp

WHERE ename = 'MAZHAR'


TASK 12

Insert a new department with this record.

Department number=50

Department name=IBIT

Location= Lahore

(Insert data of your own choice. Don’t insert data with current date)

INSERT INTO DEPT (DEPTNO, DNAME, LOC)

VALUES (50, 'IBIT', 'LAHORE')


TASK 13

Update Name of department which you have just created with name “PUCIT” anf location “mall road”.

UPDATE dept

SET dname = 'PUCIT', loc = 'Mall Road'

WHERE deptno = 50;

TASK 14
Delete department pucit.

DELETE

FROM dept

WHERE dname = 'PUCIT';

GOOD LUCK 😊

You might also like