You are on page 1of 6

Jibran-Ali 201023

create table Student(


StudentNum int primary key,
StudentName char(30),
Major char(25),
Level char(2),
age int);

create table Faculty(


FacultyID int primary key,
FacultyName char(30),
DeptID int);

create table Class(


ClassName char(40) primary key,
Meets_at char(20),
Room char(10),
FacultyID int,
FOREIGN KEY (FacultyID)
REFERENCES Faculty(FacultyID));

create table Enrolled(


StudentNum int,
FOREIGN KEY (StudentNum)
REFERENCES Student(StudentNum),
ClassName char(40),
FOREIGN KEY (ClassName)
REFERENCES Class(ClassName));

INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values


('19011','Cristopher Gracia','Computer Science','SR','22');
INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values
('19012','Karen Scott', 'Electrical Engineering','JR','24');
INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values
('19013','Hammad Anjum','Computer Science','SR','19');
INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values
('19014','Shafqat Abbas','Cyber Security','SR','20');
INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values
('19015','Sheraz Ahmed','Electrical Engineering','JR','18');
INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values
('19016','Shameer','Cyber Security','SR','19');
INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values
('19017','Ali Taqi','Computer Science','SR','20');
INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values
('19018','Mariyam','Computer Science','JR','21');
INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values
('19019','Ayesha','Computer Science','JR','23');
INSERT INTO Student(StudentNum, StudentName, Major, Level, Age) values
('19020','Humaira','Electrical Engineering','SR','24');

INSERT INTO Faculty(FacultyID, FacultyName, DeptID) values ('1071','Ivana


Teach','75');
INSERT INTO Faculty(FacultyID, FacultyName, DeptID) values ('1072','John
Williams','68');
INSERT INTO Faculty(FacultyID, FacultyName, DeptID) values ('1073','Linda
Davis','47');

INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values ('Database


Systems','0900 Hrs','68','1072');
INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values ('Organic
Chemistry','1300 Hrs','71','1071');
INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values ('Cyber
Security','1400 Hrs','54','1073');
INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values ('Urban
Economics','0830 Hrs','63','1071');
INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values
('Programming','1500 Hrs','59','1072');
INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values ('OOP','1400
Hrs','008','1072');
INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values ('Data
Structures','1000 Hrs','48','1072');
INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values ('Software
Engg','1140 Hrs','51','1072');
INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values ('Computer
Networks','1240 Hrs','37','1073');
INSERT INTO Class(ClassName, Meets_at, Room, FacultyID) values ('Digital
Forensics','1800 Hrs','69','1073');

INSERT INTO Enrolled(StudentNum, ClassName) values ('19011','Urban Economics');


INSERT INTO Enrolled(StudentNum, ClassName) values ('19011','Organic Chemistry');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19011','Urban Economics');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19012','Cyber Security');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19012','Digital Forensics');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19012','Organic Chemistry');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19013','Computer
Networks');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19013','Cyber Security');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19013','Database Systems');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19014','Software Engg');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19015','Software Engg');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19016','Computer
Networks');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19017','OOP');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19018','OOP');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19019','Data Structures');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19020','Data Structures');
INSERT INTO Enrolled(StudentNum, ClassName) values ('19020','Programming');

 Find the name of faculty members who do not teach any course. 

select distinct f.FacultyName


from faculty f where f.FacultyID not in
(select c.FacultyID from class c)

Find the names of students who are enrolled in a course taught by I.


Teach. 
select s. StudentName from student s
where s.StudentNum in
( select E. StudentNum
from class c, enrolled e, faculty f
where c. ClassName =e. ClassName and
c. FacultyID= f. FacultyID and f. FacultyID='i. Teach');
Find the names of all students who are enrolled in two classesthat meet at the 
same time. 

select distinct s.StudentName


from student s
Where s.StudentNum in
(select e1.StudentNum
from enrolled e1, enrolled e2, class c1, class c2
where e1.StudentNum =
e2.StudentNum and e1.ClassName <> e2.ClassName and e1.ClassName =
c1.ClassName and
e2.ClassName = c2.ClassName and c1.Meets_at = c2.Meets_at)

 
Find the numbers of class rooms. 

select count(*) from class;

Find student strength in each class. 

select  c. ClassName, count(*)


from  class c, enrolled e
where c.ClassName= e. ClassName
group by c.ClassName;

Find the class names, and their rooms of all classes that have fiveor more students 
enrolled in it. 
Select c. ClassName , c.Room  
From class c, enrolled e  
Where c.ClassName = e.ClassName  
Group by e.ClassName
having count(*) >= 5; 

You might also like