You are on page 1of 2

IEE 505 Fall 2011 Solutions to Homework 2

Q1. Note: The fields with underline are the primary keys. The arrow lines represent relationships.
tblCollege(CollegeID, CollegeName, Address, Phone) tblDepartment(DeptID, Name, Address, Phone, CollegeID) tblCourse(CourseID, DeptID, CourseName, TextBook, CreditHours) tblSection(SectionID, CourseID, FacultySSN, Year, Semester, Capacity) tblStudent (SSN, Name, Nationality, Gender, Phone, Email, Address, Type, class, DeptID); tblFaculty(SSN, Name, Nationality, Gender, Phone, Email, Address, JoinDate, Rank, DeptID) tblTranscript (StudentSSN, CourseID, SectionID, Grade);

Q2. create table tblCollege (CollegeID varchar(50), CollegeName varchar(50), Address varchar(50), Phone varchar(15), PRIMARY KEY(CollegeID)); create table tblDepartment (DeptID varchar(50), Name varchar(50), Address varchar(50), Phone varchar(15), CollegeID varchar(50), PRIMARY KEY(DeptID), FOREIGN KEY (CollegeID) REFERENCES tblCollege (CollegeID)); create table tblCourse (CourseID varchar(50), DeptID varchar(50), CourseName varchar(50), TexBook varchar(500), CreditHours INTEGER, PRIMARY KEY(CourseID), FOREIGN KEY (DeptID) REFERENCES tblDepartment (DeptID)); create table tblFaculty (SSN varchar(10), Name varchar(50), Nationality varchar(50),Gender varchar(5),Phone varchar(15), Email varchar(50), Address varchar(500), JoinDate Date, Rank varchar(10), DeptID varchar(50), PRIMARY KEY(SSN), FOREIGN KEY (DeptID) REFERENCES tblDepartment (DeptID)); create table tblSection (SectionID varchar(50), CourseID varchar(50), FacultySSN varchar(10), Year INTEGER, Semester varchar(50), Capacity INTEGER, PRIMARY KEY(SectionID), FOREIGN KEY (CourseID) 1

REFERENCES tblCourse (CourseID) , FOREIGN KEY (FacultySSN) REFERENCES tblFaculty(SSN)); create table tblStudent (SSN varchar(10), Name varchar(50), Nationality varchar(50), Gender varchar(5),Phone varchar(15), Email varchar(50),Address varchar(50), Type varchar(50), class varchar(50), DeptID varchar(50), PRIMARY KEY(SSN), FOREIGN KEY (DeptID) REFERENCES tblDepartment (DeptID)); create table tblTranscript (CourseID varchar(50), StudentSSN varchar(50), SectionID varchar(50), Grade double(10,2), PRIMARY KEY(CourseID, StudentSSN), FOREIGN KEY (StudentSSN) REFERENCES tblStudent (SSN), FOREIGN KEY (SectionID) REFERENCES tblSection (SectionID), FOREIGN KEY (CourseID) REFERENCES tblCourse (CourseID));

Q3. Note: the SQL commands could be different because of different table structure in Q1. a. Provide the name, SSN and department of all faculties: Select Name, SSN, DeptID from tblFaculty; b. Provide the name, SSN, department, student type of all students, order by SSN. Select Name, SSN, DeptID, Type from tblStudent order by SSN; c. Provide the course ID, the number of sections the course has, the total capacity of the course. Select C.CourseID, count(SectionID), sum(Capacity) from tblSection S, tblCourse C where S.CourseID=C.CourseID group by C.CourseID; d. List the college ID, department ID and the course IDs for that department. Select CollegeID, d.DeptID, CourseID from tblCourse c, tblDepartment d where c.DeptID= d.DeptID; e. List the course ID, section ID and the average grade of the section, order by course ID Select CourseID, SectionID, avg(Grade) from tblTranscript where group by CourseID, SectionID order by CourseID;

You might also like