Professional Documents
Culture Documents
Term Project
Dylan Dempsey, Evan Washington, and Weicong Chen 4/20/2012
Table of Contents
ER Diagram .......................................................................................................................................................... 2 Data Dictionary .................................................................................................................................................... 3 DDL Source Code ............................................................................................................................................... 10 Temporary Objects ............................................................................................................................................ 12 Surrogate Key Definitions................................................................................................................................... 13 Stored Procedures ............................................................................................................................................. 14 DML Source Code .............................................................................................................................................. 16 Change Log ........................................................................................................................................................ 23
Page 1 of 23
Entity-Relationship Diagram
Relationships: Faculty members teach classes o One faculty member may teach zero or more classes o Each class is taught by only one faculty member Each Course may have zero or one Course as a prerequisite o One prerequisite is associated with one Course Each Course becomes a specific class with a section number o One Course may have many Class offerings o One Class belongs to one Course Students enroll in classes (ClassEnrollment) o One Student has zero or more entries in classEnrollment o Each entry in classEnrollment is associated with one Student o One Class has zero or more entries in ClassEnrollment o Each entry in ClassEnrollment is associated with one Class Each Class has a grading policy o One Class has one gradingPolicy o One GradingPolicy is associated with one Class Students in ClassEnrollment turn in Assignments o Each Student enrolled in a Class has one or more assignments o One Assignment is turned in by one Student Each Assignment is associated with a GradingPolicy o Each GradingPolicy has many associated Assignments o One Assignment is associated with one GradingPolicy
Page 2 of 23
Data Dictionary
Faculty Relation schema Faculty(facultyNo, fName, lName, address, city, state, zipcode, phone) Primary Key facultyNo Alternate Key
Foreign Key
Attributes Name facultyNo Description Uniquely identifies a faculty Faculty first name Faculty last name Faculty address Faculty city Faculty state Faculty zip Faculty phone Data Type NUMERIC(10,0) Domain Characteristics Required Yes Default value
Yes Yes No No No No No
(XXX)-XXX-XXXX
Page 3 of 23
Relation schema Students(studentNo, fName, lName) Primary Key studentNo Alternate Key
Foreign Key
Attributes Name studentNo Description Uniquely identifies a student Student first name Student last name Data Type NUMERIC(10,0) Domain Characteristics Required Yes Default value
fName lName
VARCHAR(25) VARCHAR(25)
Yes Yes
Page 4 of 23
Relation schema Courses(CourseNo, cost, description, prereq) Primary Key courseNo Alternate Key
Foreign Key Prereq REFERENCES Courses(courseNo) Attributes Name courseNo Cost Description prereq Description Course Number of course Cost of course Desc of course Prereqs for course Data Type VARCHAR(10) Decimal(10, 2) VARCHAR(50) VARCHAR(10) Domain Characteristics Required Yes No Yes No Default value
Page 5 of 23
Relation schema Classes(courseNo, sectionNo, facultyNo, roomNo, hours) Primary Key courseNo, sectionNo Alternate Key
Foreign Key courseNo REFERENCES Courses(courseNo) facultyNo REFERENCES Faculty(facultyNo) Attributes Name courseNo sectionNo Description Course Number of course Section number of course Room number of course Uniquely identifies a faculty Hours of course Data Type VARCHAR(5) NUMERIC(3,0) Domain Characteristics Required Yes Yes Default value
roomNo facultyNo
VARCHAR(5) NUMERIC(10,0)
Yes Yes
Hours
NUMERIC(1,0)
Yes
Page 6 of 23
Relation schema ClassEnrollment(studentNo, courseNo, sectionNo) Primary Key studentNo, courseNo, sectionNo Alternate Key
Foreign Key studentNo REFERENCES Students(studentNo) courseNo, sectionNo REFERENCES Classes(courseNo, sectionNo) Attributes Name studentNo Description Uniquely identifies a student Course Number of course Section number of course Data Type NUMERIC(10,0) Domain Characteristics Required Yes Default value
courseNo sectionNo
VARCHAR(5) NUMERIC(3,0)
Yes Yes
Page 7 of 23
Relation schema GradingPolicy(courseNo, sectionNo, activity, weight, droplowest) Primary Key CourseNo, sectionNo Alternate Key
Foreign Key courseNo, sectionNo REFERENCES Classes(courseNo, sectionNo) Attributes Name courseNo sectionNo Activity Weight droplowest Description Course Number of course Section number of course Activity classification Percentage weight Drop lowest or not Data Type VARCHAR(5) NUMERIC(3,0) VARCHAR(10) NUMERIC(2,2) NUMERIC(1,0) Domain Characteristic Required Yes Yes Yes Yes No Default value
Page 8 of 23
Relation schema Assignment(CourseNo, sectionNo, studentNo, assignmentType, assignmentNo, grade) Primary Key courseNo, sectionNo, studentNo, assignmentType, assignmentNo Alternate Key
Foreign Key courseNo, sectionNo, studentNo REFERENCES ClassEnrollment(courseNo, sectionNo, studentNo) courseNo, sectionNo, assignmentType REFERENCES GradingPolicy(courseNo, sectionNo, activity) Attribute Name Description Data Type Domain Characteristics Require d Yes Defaul t value
courseNo
sectionNo
Grade
Course Number of course Section number of course Student ID number Assignment category Number of assignment for specified type Grade of assignment
VARCHAR(5)
NUMERIC(3,0)
Yes
NUMERIC(10,0 ) VARCHAR(10)
Yes Yes
NUMERIC(10,2 )
Yes
Page 9 of 23
KEY (facultyNo)
Students:
CREATE TABLE Students( studentNo numeric(10,0) NOT NULL, fName varchar2(25) NOT NULL, lName varchar2(25) NOT NULL, CONSTRAINT students_pk PRIMARY KEY (studentNo) );
Courses:
CREATE TABLE Courses( CourseNo varchar2(5) NOT NULL, cost numeric(10,2), description varchar2(40) NOT NULL, prereq varchar2(5), CONSTRAINT Courses_pk PRIMARY KEY (CourseNo), CONSTRAINT fk_Courses FOREIGN KEY (prereq) REFERENCES Courses(CourseNo) );
Classes:
CREATE TABLE Classes( courseNo varchar2(5) NOT NULL, sectionNo numeric(3,0) NOT NULL, facultyNo numeric(10,0) NOT NULL, roomNo varchar2(10) NOT NULL, hours numeric(1,0) NOT NULL, CONSTRAINT classes_pk PRIMARY KEY (CourseNo, sectionNo), CONSTRAINT classes_fk1 FOREIGN KEY (CourseNo) REFERENCES Courses(CourseNo), CONSTRAINT classes_fk2 FOREIGN KEY (facultyNo) REFERENCES Faculty(facultyNo) );
Page 10 of 23
ClassEnrollment:
CREATE TABLE ClassEnrollment( studentNo numeric(10,0) NOT NULL, CourseNo varchar2(5) NOT NULL, sectionNo numeric(3,0) NOT NULL, CONSTRAINT enrollment_pk PRIMARY KEY (studentNo,CourseNo,sectionNo), CONSTRAINT enrollment_fk1 FOREIGN KEY (studentNo) REFERENCES Students(studentNo), CONSTRAINT enrollment_fk2 FOREIGN KEY (CourseNo, sectionNo) REFERENCES Classes(CourseNo, sectionNo) );
GradingPolicy:
CREATE TABLE GradingPolicy( CourseNo varchar2(5) NOT NULL, sectionNo numeric(3,0) NOT NULL, activity varchar2(10) NOT NULL, weight numeric(2,2) NOT NULL, dropLowest numeric(1,0), CONSTRAINT grading_pk PRIMARY KEY (CourseNo, sectionNo, activity), CONSTRAINT grading_fk FOREIGN KEY (CourseNo, sectionNo) REFERENCES Classes(CourseNo, sectionNo) );
Assignment:
CREATE TABLE Assignment( CourseNo varchar2(5) NOT NULL, sectionNo numeric(3,0) NOT NULL, studentNo numeric(10,0) NOT NULL, assignmentType varchar2(10) NOT NULL, assignmentNo numeric(2,0) NOT NULL, grade numeric(10,2) NOT NULL, CONSTRAINT assignment_pk PRIMARY KEY (CourseNo, sectionNo, studentNo, assignmentType, assignmentNo), CONSTRAINT assignment_fk1 FOREIGN KEY (studentNo, CourseNo, sectionNo)
Page 11 of 23
Temporary Objects
VIEW Get Grades calculates final scores for all students in all sections of all courses.
Page 12 of 23
Page 13 of 23
Stored Procedures
Logical Design
Procedure Name CalcGradeReport Inputs Course number Section number Outputs Ref Cursor for storing results Logic Flow This procedure gets the course number, section number, and score from the View GetGrades and relates these values to student names by matching the student numbers, then, returns only those values for the specified Course and Section This procedure gets the course number, section number, and score from the View GetGrades and relates these values to student names by matching the student numbers. Then, returns only those values for the specified student first and last names. This procedure gets the course number and counts the student numbers for each course, then returns course number and student count for only the specified course number. This procedure gets the course number and counts the student numbers for each course then matches the course number to a description by matching course numbers. Returns course number and student count for only the specified course number.
CalcTranscript
CourseInfo
Page 14 of 23
Source Code
CalcGradeReport:
CREATE OR REPLACE PROCEDURE CalcGradeReport(cNo IN VARCHAR2, sNo IN VARCHAR2, p_cursor OUT SYS_REFCURSOR) AS BEGIN OPEN p_cursor FOR SELECT s.lName, s.fName, g.courseNo, g.sectionNo, g.score FROM GetGrades g JOIN Students s ON g.studentNo = s.studentNo WHERE g.courseNo = cNo AND g.sectionNo = sNo; END CalcGradeReport; . RUN;
CalcTranscript:
CREATE OR REPLACE PROCEDURE CalcTranscript(stufName IN VARCHAR2, stulName IN VARCHAR2, p_cursor OUT SYS_REFCURSOR) AS BEGIN OPEN p_cursor FOR SELECT s.lName, s.fName, g.courseNo, g.sectionNo, g.score FROM GetGrades g JOIN Students s ON g.studentNo = s.studentNo WHERE s.fName = stufName AND s.lName = stulName; END CalcTranscript; . RUN;
CourseEnrollment:
CREATE OR REPLACE PROCEDURE CourseEnrollment(cNo IN VARCHAR2, p_cursor OUT SYS_REFCURSOR) AS BEGIN OPEN p_cursor FOR SELECT courseNo, stuCount FROM( SELECT courseNo, COUNT(studentNo) AS stuCount FROM ClassEnrollment GROUP BY courseNo ) WHERE courseNo = cNo; END CourseEnrollment; . RUN;
CourseInfo:
CREATE OR REPLACE PROCEDURE CourseInfo(cNo IN VARCHAR2, p_cursor OUT SYS_REFCURSOR) AS BEGIN OPEN p_cursor FOR SELECT c1.courseNo, c2.description, c1.stuCount FROM( SELECT courseNo, COUNT(studentNo) AS stuCount FROM ClassEnrollment GROUP BY courseNo ) c1 JOIN( SELECT courseNo, description FROM Courses ) c2 ON c1.courseNo = c2.courseNo WHERE c1.courseNo = cNo; END CourseInfo; . RUN;
Page 15 of 23
Page 16 of 23
3.) How many different instructors? List their names and classes taught respectively. Order results by instructor last name.
SELECT COUNT(*) AS InstructorCount FROM Faculty;
SELECT F.lname, F.fname, c.CourseNo, c.SectionNo FROM Faculty F LEFT OUTER JOIN Classes C ON f.facultyNo=C.facultyNo ORDER BY lname ASC;
Page 17 of 23
Page 18 of 23
4.) How many students enrolled in a given course (For example, CS20, Intro to Computers)?
VAR rc REFCURSOR EXEC CourseEnrollment(CS20,:rc); Print rc
Page 19 of 23
5.) Generate grade report for any given class/section (For example, CS25, Section 4) Order results by student last name.
VAR rc Refcursor EXEC CalcGradeReport('CS25', '4',:rc); Print rc
6.) Generate transcript for any given student with first name and last name only. (For example, student Yvonne Williams) Order results by ascending order of course number.
VAR rc REFCURSOR EXECUTE CalcTranscript('Yvonne','Williams',:rc); Print rc
Page 20 of 23
7.) List course number, course description, and total number of students enrolled for any given course. (For example, CS20, Intro to Computers)
VAR rc REFCURSOR EXEC CourseInfo(CS20, :rc); Print rc
8.) List instructors name associated with generated revenue for all instructors. Order your results by amount of revenue in descending order.
SELECT fName,lName, facultyNo, TO_CHAR(SUM(COALESCE(classRev,0)), $9,999,999.00) AS Revenue FROM( SELECT c1.courseNo, c1.sectionNo, (c2.cost*c1.stuCount) AS classRev FROM( SELECT courseNo, sectionNo, COUNT(studentNo) AS stuCount FROM ClassEnrollment GROUP BY courseNo, sectionNo ) c1 JOIN( SELECT courseNo, cost FROM Courses co ) c2 ON c1.courseNo = c2.courseNo and c1.courseNo = c2.courseNo ) crs RIGHT JOIN( SELECT f.fName, f.lName, f.facultyNo, courseNo, sectionNo FROM Classes c RIGHT JOIN faculty f ON c.facultyNo = f.facultyNo ) cls ON crs.courseNo = cls.courseNo AND crs.courseNo = cls.courseNo GROUP BY fName, lName, facultyNo ORDER BY Revenue DESC;
Page 21 of 23
Page 22 of 23
Change Log
The following changes have been made to the original logical design: Faculty Table o Attributes address, city, state, zipcode, and phone are no longer required Students o No changes Class o Class has been split into two separate tables Courses Consists of attributes courseNo, cost, description, and prereq Added prereq foreign key constraint that references courseNo to prevent inserting prerequisites for nonexistent classes Values for cost and prereq can now be NULL Classes Consists of attributes courseNo, sectionNo, facultyNo, room, and hours Added foreign key constraint courseNo, referencing Courses table Added foreign key constraint facultyNo referencing Faculty table CourseRecords o This table is now called classEnrollment o Primary constraint key has been added for courseNo, sectionNo, and studentNo to prevent students from registering for the same class multiple times GradingPolicy o Attributes participation, homework, quiz, midterm, and final have been replaced with a single attribute, activity o Primary key constraint has been updated to include courseNo, sectionNo, and activity Assignment o Attribute assignmentID has been changed to assignmentNo o Old foreign key has been dropped o Added foreign key constraint courseNo, sectionNo, studentNo referencing ClassEnrollment table o Added foreign key constraint courseNo, sectionNo, assignmentType referencing grading policy
Page 23 of 23