Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Submitted By: Zain

Saleem

Roll No. : F18BA138

Section: Afternoon ‘A’

Subject: Database Management System

Submitted To: Sir Saleem Raza


Roll No.: A03-F18-BBIT-MA & EA

Name: Relational Database Management System

Question No 01. 30
Following is the Relational Schema of Course Registration Systems of an institute
Degree(DCode, Title, DCH, Sem)
Students(RegNo, Name, Gender, DoB, City, DCode)
Courses(CCode, CTitle, CH, Sem, DCode)
Faculty(FCode, Name, Designation, eMail, City)
Term(TCode, Description, MidWeek, FinalWeek)
CRS(RegNo, CCode, TCode, OM, Grade)
Teach(FCode, CCode, TCode, Section, FB, NoS) // FB-> Feedback, NoS-? No. of Students
Write the SQL Statements for followings:
i. List the Courses which are not offered in term ‘S15’ but were offered in ‘S14’ 5

SELECT CCode
FROM CRS
WHERE TCode='S14' AND CCode NOT IN
(SELECT CCode
FROM CRS
WHERE TCode='S15');

ii. List the Courses which are not taught by any Faculty in ‘S15’ 5

SELECT CCode
FROM Teach
WHERE CCode NOT IN
(SELECT CCode
FROM Teach
WHERE TCode='S15');

iii. List Faculty who has taught ‘BF-357’ and ‘EC-123’ but have NEVER taught ‘CS-137’ 5

SELECT FCode
FROM Teach
WHERE CCode='BF-357' OR CCode='EC-123' AND FCode NOT IN
(SELECT FCode
FROM Teach
WHERE CCode='CS-137');

May 2020 Page 2 of 5


iv. List the Course which are being taught by ‘Lecturers’ during term ‘S17’ which were taught by ‘Professor’
during term ‘S15’. 5

SELECT CCode
FROM Faculty INNER JOIN Teach ON Faculty.FCode=Teach.FCode
WHERE Designation='Lecturer' AND TCode='S17' AND CCode IN
(SELECT CCode
FROM Faculty INNER JOIN Teach ON Faculty.FCode=Teach.FCode
WHERE Designation='Professor' AND TCode='S15');

v. List the Students Name with Course Titles of students who are enrolled only in those courses during
term ‘S17’ in which students have secured ‘A’ in term ‘S15’. 5

SELECT Name, CTitle

FROM (Courses INNER JOIN CRS ON Courses.CCode=CRS.CCode) INNER JOIN


Students ON CRS.RegNo=Students.RegNo
WHERE CRS.TCode='S17' AND Students.RegNo IN
(SELECT Students.RegNo
FROM Courses INNER JOIN CRS ON Courses.CCode=CRS.CCode
WHERE CRS.TCode='S15' AND CRS.Grade='A');

vi. List the Students who are enrolled in courses offered in even semesters of the ‘BBIT’ 5

SELECT Name, Sem


FROM (CRS INNER JOIN Students ON CRS.RegNo=Students.RegNo)
INNER JOIN Course ON CRS.CCode=Course.CCode
WHERE Sem='2' OR Sem='4' OR Sem='6' OR Sem='8';
Question No 02. 10
Consider the following database instance
Teachers IS-QUALIFIED SECTION
TCNIC TName TCNIC CCOde Qualify SCode CCode
4210 Imran 4240 CS104 8/96 2912 CS201
4220 Shoaib 4220 CS201 8/95 2913 CS201
4230 Qadeer 4220 CS402 8/95 2914 CS204
4240 Sara 4210 CS201 8/96 2915 CS402
4210 CS204 8/96 2916 CS303
4230 CS204 8/95
STUDENT COURSE IS-REGISTERED
RegNo RegNo SCode Term
StdName CCode CTitle PreReq 214 2914 SP09
214 Alia CS104 C Programming NULL 107 2914 SP09
107 Tahreem CS201 Data Structures CS104 107 2915 SP09
324 Isbah CS204 Database Systems CS201 324 2913 SP09
542 Izaan CS402 Compiler Design CS201 214 2916 F09
410 Fatima CS303 Software Engineering CS204 542 2914 F09
Write the following queries in SQL Statement for following.
i. Retrieve the names of all students, which were not enrolled in any courses during semester ‘SP09’ 5
Sample Output of query for the above given state database:
StdName
Izaan
Fatima

SELECT StdName
FROM Student
WHERE RegNo NOT IN
(SELECT RegNo

FROM IsRegistered
WHERE Term='SP09');

ii. Retrieve the Course Title, Pre-Req Course, and Qualified Faculty Name for all courses. 5
Sample Output of query for the above given state database:
Course Title Pre Requisite Course Qualified Faculty Name
C Programming NULL Sara
Data Structures C Programming Shoaib
Data Structures C Programming Imran
Database Systems Data Structures Imran
Database Systems Data Structures Qadeer
Compiler Construction Data Structures Shoaib
Software Engineering Database Systems NULL

SELECT CTitle, PreReq, TName


FROM (Courses LEFT JOIN ISQualified ON Courses.CCode=ISQualified.CCode)
LEFT JOIN Teachers ON ISQualified.TCNIC=Teachers.TCNIC;
Question No 03. 20
Consider the relation schemas as follows.
Works(pName, cTitle, salary);
Lives(pName, Street, pCity);
Company(cTitle, cCity);
managers(pName, mName); where mName refers to Works(pName).
a. Find the names of the persons who live and work in the same city. 4
SELECT Works.pName
FROM (Company INNER JOIN Works ON Company.cTitle=Works.cTitle) INNER JOIN Lives ON Works.pName=Lives.pName

WHERE Company.cCity=Lives.pCity;
b. Find the persons whose salaries are more than the salary of everybody working with company ’SBC’. 4
SELECT pName

FROM Works
WHERE Salary>ALL
(SELECT Salary
FROM Works
WHERE cTitle='SBC');

c. Find the names of the companies which is located-in every city where company ’SBC’ is located-in. 4

SELECT cTitle

FROM Company
WHERE cCity IN
(SELECT cCity
FROM Company
WHERE cTitle='SBC');
d. List names of person along with company who lives in different city than the city of their company 4
SELECT Works.pName, Works.cTitle
FROM (Company INNER JOIN Works ON Company.cTitle=Works.cTitle)
INNER JOIN Lives ON Works.pName=Lives.pName
WHERE Company.cCity<>Lives.pCity;
e. List names of persons, Company City and Salary; who are 2 managerial levels below the person ‘Ali’ 4

SELECT *

FROM (SELECT*
FROM managers
WHERE mName IN
(SELECT pName
FROM managers
WHERE mName IN
(SELECT pName
FROM managers
WHERE pName='Ali')))
Finish Line
Nothing beyond this line will be evaluated

You might also like