1. ITCS 3160 Database Design and Implementation
mySQL Report
Tanguy Bousole-Tamsi
Yasser Meza
Sylvester Mensah
7th December 2016
Dr. Pamela Thompson
T.A Venkata Vaishnavi
The purpose of this report is to show the implementation of a database that
stores the extracurricular activities of undergraduate students. The report also shows
the creation of specific reports for college departments and sponsors.
Business Rules:
-Person will be any student/faculty/staff
-Student can have only one faculty advisor
-An Event can have only one sponsor(Person)
-A Person can sponsor zero to many events
-Students can sign up to one or many events
-Events can have one to many students
-All Events require Evaluation form from Students that asks
Was the event useful? 1-5
Would you recommend to another student? 1-5
Was the event relative to your major? 1-5
-Faculty need a report listing the advisees(Students) and the Events they attended.
-Sponsors need report of individual event and average of ratings.
2. -Students need to list Events they have registered for and attended.
EERD
SQL Statements:
A- Create For each table:
CREATE TABLE `evaluation` (
`Person_Person_ID` int(11) NOT NULL,
`Event_Event_ID` varchar(45) DEFAULT NULL,
`Useful` int(11) DEFAULT NULL,
`Recommend` int(11) DEFAULT NULL,
`MajorRelated` int(11) DEFAULT NULL,
`Person_Person_ID1` int(11) NOT NULL,
`Events_Event_ID` int(11) NOT NULL,
`Events_Person_Person_ID` int(11) NOT NULL,
`Events_Event_ID1` int(11) NOT NULL,
`Events_Person_Person_ID1` int(11) NOT NULL,
PRIMARY KEY
(`Person_Person_ID`,`Person_Person_ID1`,`Events_Event_ID`,`Events_Person_Person_ID`,`E
vents_Event_ID1`,`Events_Person_Person_ID1`),
KEY `fk_Evaluation_Person1_idx` (`Person_Person_ID1`),
KEY `fk_Evaluation_Events1_idx` (`Events_Event_ID1`,`Events_Person_Person_ID1`),
CONSTRAINT `fk_Evaluation_Events1` FOREIGN KEY (`Events_Event_ID1`,
`Events_Person_Person_ID1`) REFERENCES `events` (`Event_ID`, `Person_Person_ID`) ON
DELETE NO ACTION ON UPDATE NO ACTION,
3. CONSTRAINT `fk_Evaluation_Person1` FOREIGN KEY (`Person_Person_ID1`)
REFERENCES `person` (`Person_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `department` (
`Dept_ID` int(11) NOT NULL AUTO_INCREMENT,
`Dept_Name` varchar(45) DEFAULT NULL,
PRIMARY KEY (`Dept_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `events` (
`Event_ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` varchar(45) DEFAULT NULL, `Description` varchar(45) DEFAULT NULL,
`Date/Time` datetime DEFAULT NULL, `length` int(11) DEFAULT NULL,
`Location` varchar(45) DEFAULT NULL, `Sponsor_ID` int(11) DEFAULT NULL,
`Person_Person_ID` int(11) NOT NULL, PRIMARY KEY (`Event_ID`,`Person_Person_ID`),
KEY `fk_Events_Person1_idx` (`Person_Person_ID`), CONSTRAINT `fk_Events_Person1`
FOREIGN KEY (`Person_Person_ID`) REFERENCES `person` (`Person_ID`) ON DELETE NO
ACTION ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `faculty` (
`Highest_Degree` varchar(45) DEFAULT NULL,
`Hire_Year` datetime DEFAULT NULL,
`Person_Person_ID` int(11) DEFAULT NULL,
`Person_Person_ID1` int(11) NOT NULL,
PRIMARY KEY (`Person_Person_ID1`),
CONSTRAINT `fk_Faculty_Person1` FOREIGN KEY (`Person_Person_ID1`) REFERENCES
`person` (`Person_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `person` (
`Person_ID` int(11) NOT NULL AUTO_INCREMENT,
`Fname` varchar(45) DEFAULT NULL, `MInt` varchar(45) DEFAULT NULL,
`Address` varchar(45) DEFAULT NULL, `City` varchar(45) DEFAULT NULL,
`State` varchar(45) DEFAULT NULL, `Phone` int(11) DEFAULT NULL,
`zip` int(11) DEFAULT NULL, `email` varchar(45) DEFAULT NULL,
`Department_Dept_ID` int(11) DEFAULT NULL, `Department_Dept_ID1` int(11) NOT NULL,
PRIMARY KEY (`Person_ID`), KEY `fk_Person_Department1_idx` (`Department_Dept_ID1`),
CONSTRAINT `fk_Person_Department1` FOREIGN KEY (`Department_Dept_ID1`)
REFERENCES `department` (`Dept_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `staff` (
`Pos_Title` varchar(45) DEFAULT NULL, `SupervisorYorN` tinyint(1) DEFAULT NULL,
`Person_Person_ID` int(11) DEFAULT NULL, `Person_Person_ID1` int(11) NOT NULL,
PRIMARY KEY (`Person_Person_ID1`), CONSTRAINT `fk_Staff_Person1` FOREIGN KEY
(`Person_Person_ID1`) REFERENCES `person` (`Person_ID`) ON DELETE NO ACTION ON
UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `student` (
4. `Major_ID` int(11) DEFAULT NULL, `SAT_Score` double DEFAULT NULL,
`HS_GPA` double DEFAULT NULL, `On_Campus_YorN` tinyint(1) DEFAULT NULL,
`Person_Person_ID` int(11) DEFAULT NULL, `Person_Person_ID1` int(11) NOT NULL,
PRIMARY KEY (`Person_Person_ID1`), CONSTRAINT `fk_Student_Person1` FOREIGN KEY
(`Person_Person_ID1`) REFERENCES `person` (`Person_ID`) ON DELETE NO ACTION ON
UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `studentevents` (
`Person_Person_ID` int(11) NOT NULL, `Event_Event_ID` int(11) NOT NULL,
`StudentRegistration` varchar(45) DEFAULT NULL, `Student_Person_Person_ID1` int(11)
NOT NULL, `Evaluation_Person_Person_ID` int(11) NOT NULL,
`Evaluation_Person_Person_ID1` int(11) NOT NULL,
`Evaluation_Events_Event_ID` int(11) NOT NULL,
`Evaluation_Events_Person_Person_ID` int(11) NOT NULL,
PRIMARY KEY
(`Person_Person_ID`,`Event_Event_ID`,`Student_Person_Person_ID1`,`Evaluation_Person_Pe
rson_ID`,`Evaluation_Person_Person_ID1`,`Evaluation_Events_Event_ID`,`Evaluation_Events_
Person_Person_ID`),
KEY `fk_StudentEvents_Student1_idx` (`Student_Person_Person_ID1`),
KEY `fk_StudentEvents_Evaluation1_idx`
(`Evaluation_Person_Person_ID`,`Evaluation_Person_Person_ID1`,`Evaluation_Events_Event_
ID`,`Evaluation_Events_Person_Person_ID`),
CONSTRAINT `fk_StudentEvents_Evaluation1` FOREIGN KEY
(`Evaluation_Person_Person_ID`, `Evaluation_Person_Person_ID1`,
`Evaluation_Events_Event_ID`, `Evaluation_Events_Person_Person_ID`) REFERENCES
`evaluation` (`Person_Person_ID`, `Person_Person_ID1`, `Events_Event_ID`,
`Events_Person_Person_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_StudentEvents_Student1` FOREIGN KEY (`Student_Person_Person_ID1`)
REFERENCES `student` (`Person_Person_ID1`) ON DELETE NO ACTION ON UPDATE NO
ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
B- Insert For each table:
INSERT INTO department(Dept_ID, Dept_Name) VALUES (2, 'Medecine');
INSERT INTO `mydb`.`staff` (`Pos_Title`, `SupervisorYorN`, `Person_Person_ID`,
`Person_Person_ID1`) VALUES ('Advisor', 'Y', '2', '2');
INSERT INTO `evaluation` (`Person_Person_ID`, `Event_Event_ID`, `Useful`, `Recommend`,
`MajorRelated`, `Person_Person_ID1`, `Events_Event_ID`, `Events_Person_Person_ID`,
`Events_Event_ID1`, `Events_Person_Person_ID1`) VALUES ('1', '2', '4', '3', 'yes', '1', '2', '1', '1',
'1');
INSERT INTO `mydb`.`events`
(`Event_ID`, `Name`, `Description`, `Date/Time`, `length`, `Location`,
`Sponsor_ID`, `Person_Person_ID`) VALUES (<{Event_ID: }>, <{Name: }>, <{Description: }>,
<{Date/Time: }>, <{length: }>, <{Location: }>, <{Sponsor_ID: }>, <{Person_Person_ID: }>);
6. Trigger
CREATE TABLE Department_Update(
Dept_ID INT AUTO_INCREMENT PRIMARY KEY,
Dept_Name VARCHAR(45) DEFAULT NULL
);
CREATE TRIGGER `Department_Update` BEFORE UPDATE ON `department` FOR EACH
ROW INSERT INTO department_update SET Dept_Name = 'update', Dept_ID = OLD.Dept_ID;
7. Example of Delete and Update For One Table:
A. Delete
DELETE FROM `person` WHERE `person`.`Person_ID` = 6
B. Update
UPDATE `mydb`.`events` SET `Date/Time`='13142012 00:00:00' WHERE `Event_ID`='1'
and`Person_Person_ID`='1';
SQL For The Views of Four Reports
1- Faculty need to receive a report listing their advisees and events that the advisees attended
8. CREATE ALGORITHM = UNDEFINED VIEW `EventAdvisees` AS SELECT `person`.`Fname`,
`events`.`Name` FROM `person` LEFT JOIN `events` ON `events`.`Person_Person_ID` =
`person`.`Person_ID`
2- Sponsors need to receive a report of an individual event and the average of the ratings
SELECT `events`.`Name`, `evaluation`.`Useful`, `evaluation`.`Recommend`
FROM `events`
LEFT JOIN `evaluation` ON `evaluation`.`Events_Event_ID1` = `events`.`Event_ID` AND
`evaluation`.`Events_Person_Person_ID1` = `events`.`Person_Person_ID`
9. 3- Students need to be able to list the events of a particular type
4- Person needs to list all faculty with their highest degree
SELECT `person`.`Fname`, `person`.`MInt`, `faculty`.`Highest_Degree` FROM `person` LEFT
JOIN `faculty` ON `faculty`.`Person_Person_ID1` = `person`.`Person_ID` ORDER BY `Fname`
ASC
11. INDEXES
CREATE INDEX FNameIndex ON Person(Fname);
SELECT Fname from person;
SELECT Fname from person ORDER BY `Fname` ASC
CREATE INDEX `fk_Person_Department1_idx` ON `mydb`.`person` (`Department_Dept_ID1`
ASC);
CREATE INDEX `fk_Events_Person1_idx` ON `mydb`.`events` (`Person_Person_ID` ASC);
CREATE INDEX `fk_Evaluation_Person1_idx` ON `mydb`.`evaluation` (`Person_Person_ID1`
ASC);
CREATE INDEX `fk_StudentEvents_Student1_idx` ON `mydb`.`studentevents`
(`Student_Person_Person_ID1` ASC);