You are on page 1of 24

JAX Professional Center

Term Project
Dylan Dempsey, Evan Washington, and Weicong Chen 4/20/2012

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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

fName lName Address City State Zipcode phoneNumber

VARCHAR(25) VARCHAR(25) VARCHAR(30) VARCHAR(25) VARCHAR(2) NUMERIC(5,0) VARCHAR(13)

Yes Yes No No No No No

(XXX)-XXX-XXXX

Enterprise constraints None

Page 3 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington


Students

January 26, 2013 Weicong Chen

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

Enterprise constraints None

Page 4 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington


Courses

January 26, 2013 Weicong Chen

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

Enterprise constraints None

Page 5 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington


Classes

January 26, 2013 Weicong Chen

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

Enterprise constraints None

Page 6 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington


ClassEnrollment

January 26, 2013 Weicong Chen

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

Enterprise constraints None

Page 7 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington


GradingPolicy

January 26, 2013 Weicong Chen

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

Enterprise constraints None

Page 8 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington Assignment

January 26, 2013 Weicong Chen

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

studentNo assignmentType assignmentNo

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

Enterprise constraints None

Page 9 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

DDL Source Code


Faculty:
CREATE TABLE Faculty( facultyNo numeric(10,0) fName varchar2(25) lName varchar2(25) address varchar2(30), city varchar2(25), state varchar2(2), zipCode numeric(5,0), phone varchar2(13), CONSTRAINT faculty_pk PRIMARY ); NOT NULL, NOT NULL, NOT NULL,

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

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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)

REFERENCES ClassEnrollment(studentNo, CourseNo, sectionNo),


CONSTRAINT assignment_fk2 FOREIGN KEY (CourseNo, sectionNo, assignmentType) REFERENCES GradingPolicy(courseNo, sectionNo, activity) );

Page 11 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

Temporary Objects
VIEW Get Grades calculates final scores for all students in all sections of all courses.

Source Code for View GetGrades


CREATE OR REPLACE VIEW GetGrades AS SELECT COURSENO,SECTIONNO,STUDENTNO, TO_CHAR(SUM(SCORE), 00.00) as score FROM( SELECT courseno,sectionno,studentno , assignmenttype, Case When droplowest = 1 then (sum(Score)- min(Score))/(count(*)-1) Else sum(score)/count(*) End as score From( Select aa.courseno, aa.sectionno, aa.studentno, aa.assignmenttype, aa.assignmentno, aa.score,gg.droplowest From( Select courseno,sectionno,studentno,assignmenttype,assignmentno, sum(weight * grade) as score From( Select a.courseno,a. sectionno, a.studentno,a. assignmenttype,a.assignmentno,g.weight,a. grade From assignment a Join Gradingpolicy g On a.sectionno = g.sectionno and a.courseno = g.courseno and a.assignmenttype = g.activity) group by courseno,sectionno,studentno,assignmenttype,assignmentno) aa join gradingpolicy gg on aa.sectionno = gg.sectionno and aa.courseno = gg.courseno and aa.assignmenttype = gg.activity order by studentno) group by courseno,sectionno,studentno , assignmenttype,droplowest order by studentno) GROUP BY COURSENO,SECTIONNO,STUDENTNO ORDER BY COURSENO;

Page 12 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

Surrogate Key Definitions


The following surrogate keys were used in this logical design: studentNo o A unique integer value assigned to students, beginning with 1. o studentNo identifies students. o It is incremented based on alphabetical order of last names. o This value is used to relate students to the courses they are taking and the assignments they turn in for those courses. facultyNo o A unique integer value assigned to faculty members, beginning with 1. o facultyNo identifies faculty members. o It is incremented based on alphabetical order of last names. o This value is used to relate faculty members with the courses they teach assignmentType o Identifies the type of assignment (i.e. PA, HM, QZ, Midterm, Final) o This value is used to relate the Assignment and GradingPolicy tables through a foreign key relationship. assignmentNo o Identifies the number of the assignment for a given class. o For example, if CS20 Section 1 has two assignments of assignmentType QZ then the assignmentNo for these assignments would be 1 and 2.

Page 13 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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

Student first name Student last name

Ref Cursor for storing results

CourseEnrollment Student first name Student last name

Ref Cursor for storing results

CourseInfo

Student first name Student last name

Ref Cursor for storing results

Page 14 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

DML Query Source Code


Set pagesize 1000 Set linesize 1000 1.) List detail of all different courses (neither class nor section) for this institute.
SELECT * FROM COURSES;

Page 16 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

2.) How many active students stored in current database application?


SELECT COUNT(studentNo) FROM( SELECT DISTINCT studentNo FROM ClassEnrollment );

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

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

Page 18 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

Page 22 of 23

CS501 Dylan Dempsey

Jax Profession Center Term Project Evan Washington

January 26, 2013 Weicong Chen

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

You might also like