You are on page 1of 28

University Database Management System

2015
Semester: 4
Course: Database Management System
and

Project: University Database Management System (Academics


Research)

Team Members:
Kavi Pandya (131020): pandyakavi31@gmail.com
Mayank Jobanputra (131026): mayankjobanputra@gmail.com
Urvika Sonar (131060): urvikasonar@gmail.com
Preksha Chavda (121036): prekshachavda99@gmail.com

University Database Management System


Contents:
1.
2.
3.
4.
5.
6.
7.

Problem Statement
Project Description
List of Entities
Normalization of forms
Relational Database Schema
List of Queries
Database Programming:
a. Stored Procedure
b. Triggers
c. Java Connectivity
8. References

University Database Management System

1. Problem Statement:
University Database Management System creates, manages and
performs all the activities related to the database of a given
university. The database consists of information about the
university, colleges, students, faculties, academic and research
programs. The main aim of this project is to manage the
database in such a way that information about academic and
research activities can be retrieved easily, efficiently and
accurately.
2. Project Description:
A university has different institutes affiliated with it. These
institutes have various programs that offer degrees in different
departments. Students and faculties of these institutes are
associated with different academic and research programs.
Student enrolls for a particular program in a particular
department. This program consists of various courses.
Experienced faculties teach these courses. Some of these faculty
members are permanent while some are visiting. These courses
have predefined course structure that includes lectures, projects,
assignments, quizzes and exams for which students have to
appear and are evaluated throughout the semester. Teaching
assistants and associates are appointed for various courses that
work under the guidance of the respective faculties teaching that
particular course.
As the institute follows unique project based approach student
takes various research projects apart from the academic projects
and are mentored by the faculties. Seminars, talks and
workshops are held for academic and research purposes.
Faculties are also associated with different research projects.
Research staff accompanies these faculties that consists of
students, teaching assistants and associates and other faculty
members if any. Different organizations and the university itself
fund these research projects. Such research projects have
defined time frame. Many papers are published for these
research projects. Successful projects are further applied for
patents.
3. List of Entities:

University Database Management System


1. Assignment_Course_structure
2. Assignments
3. Assignments_has_TA
4. Author_Faculty
5. Author_Student
6. Class
7. Course_type
8. Courses
9. Courses_has_Course_type
10. Courses_has_Department
11. Courses_has_Topics
12. Department
13. Department_has_Faculty
14. Department_has_Program
15. Exams
16. Exams_has_course_structure
17. Faculty
18. Faculty_has_course_structures
19. Funding
20. Grade_Points
21. Grades
22. Internal_Project_has_TA
23. Mentor_has_Research_Topics
24. Offerings_Semester
25. Offerings_Semester_has_Courses
26. Paper
27. Paper_has_Author
28. Patents
29. Prerequisites
30. Program
31. Project
32. Project_has_Student
33. Project_has_Topics
34. Quiz_of_courses
35. Quizzes
36. Research_Projects
37. Research_Projects_has_Faculty
38. Research_Projects_has_Funding
39. Research_Projects_has_Paper
40. Research_Projects_has_Research_Topics
41. Research_Projects_has_Student
42. Research_Topics
43. Section
44. Section_has_course_structures
45. Semester
46. Seminars

University Database Management System


47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.

Seminars_has_Mentor
Status
Structure_Course
Structure_Course_has_Topics
Student
Student_has_Assignments
Student_has_Exams
Student_has_Quizzes
Student_has_Section_has_course_structures
TA_has_Offerings_Semester
Teaching_Assistants
Teaching_Associates
Time_Schedule
Topics
Visiting_mentor
Workshops
Workshops_has_Class
Workshops_has_Mentor
Workshops_has_Research_Topics

4. Normalization of forms:
It may be possible that in database there are tables created
which has repetitive data and several anomalies, which can
cause inconsistency of data. Normalization is applied to solve
this problem. It helps in solving below listed points:
1. Removing Redundancy:
For example,
a. Funding table containsinformation only about the
funding organizations. It does not include the research
projects that are funded by these organizations.
Information, about which organization is funding which
project, is kept in a separate table. It is done so because
it may be possible that an organization may be funding
more than one research projects and keeping both these
columns in the same table would have resulted in
redundant data, so to avoid this problem normalization
is applied and tables are separated.
b. Department table contains information about the
departments of the institute. Program table contains
information regarding the programs offered in different
departments. Both of these tables are kept separate
because many departments have same programs being
offered and keeping them in the same table would have

University Database Management System

resulted in redundant data. Thus, normalization is


applied and tables are separated and a table named
department_has_program is created which links both of
these tables and gives the required information.
2. Avoiding Null Values:
Faculty table contains information about the faculties.
Research_Topics table contains information about the
research topics that are currently being worked on or are
completed. These two table are kept separate because it
may be possible that some of the faculty members are not
working on any research projects and keeping both of
these in same table would have resulted in null values in
some of the entries. So to avoid this problem,
normalization is applied and tables are separated and a
table named Research_Projects_has_Faculty is created both
of above mentioned tables and gives information.
3. Update Anomali:
Courses table consists of information regarding the courses
that are offered. Offering_Semesters table contains
information about offering time of a particular semester. It
may happen that a course was offered in some different
semester earlier and presently it is being offered in some
another semester. Keeping this data in same table would
result in update anomali because while updating, past data
would be lost from the records because of the semester
change in the offereing of a particular course. So to avoid this
update anomaly, normalization is applied and a table named
Offerings_semester_has_courses is created which keeps
record of each and every course offering time.
4. Loss of data when deleting:
Structure_Course table contains information about the course
structure of a particular course. Topics table contains
information about all the topics taught. If both of these are
kept in one table and if assumption is made that a particular
topics was included in one of the course structure earlier and
removed now then it will lead to loss of record of that topic
from that table resulting in delete anomali, so to avoid that,
normalization is applied and a table named
Structure_Course_has_Topics is created which links above
mentioned tables so that no data is lost and required
information is retrieved.

University Database Management System

5. Relational Database Schema- Add machine generated Line Code


here
6. List of Queries:

I.

FIND STUDENT NAME GIVEN FOLLOWING CONSTRAINTS ON ATTENDANCE>7, QUIZ>7,

ASSIGNMENT>15, PROJECT>43, MID-EXAM>30 AND FINAL EXAM>35

select first_name, middle_name, last_name, student_id from student


where student_id in
(select distinct student_id from student_section_course_struct
where course_section_id=1
and
attendence > 7
and student_id in
(select distinct student_id from student_quiz
where quiz_id=(select quiz_id from course_quiz where course_section_id=1)
and
marks > 7) and student_id in
(select distinct student_id from student_assignments
where assignment_id=(select assignment_id from assignment_course_structure where course_section_id=1)
and
marks > 15) and student_id in
(select distinct student_id from project_has_student
where internal_project_id=(select project_id from project where course_section_id=1)
and marks > 43) and student_id in
(select distinct student_id from student_exams
where exam_id=(select exam_id from exams where exam_id in (select exam_id from exam_course_structure
where course_section_id=1)
and exam_type='MID')
and marks > 30) and student_id in
(select distinct student_id from student_exams
where exam_id=(select exam_id from exams where exam_id in (select exam_id from exam_course_structure
where course_section_id=1)
and exam_type='FINAL')
and marks > 35)
)

II.

List of all the course_structure_id and name that are being offered currently.

select course_structure_id, course_id from course_structure where course_structure_id in


(select distinct course_structure_id from section_course_structure where course_section_id in
(select course_section_id from student_section_course_struct where status_id = 'C')) order by course_structure_id;

University Database Management System

III.

Average marks of students within given quiz_id. Here given quiz_id is taken as 1

select sum(marks)/count(student_id) as 'Average Quiz Marks' , total_marks as 'Total Quiz Marks'


from student_quiz,quizzes
where student_quiz.quiz_id=1 and quizzes.quiz_id=1;

IV.

Student getting highest marks in give assignment

set @highest_marks=(select marks from student_assignments where assignment_id=1 order by marks desc limit 1,1);
select first_name, middle_name, last_name, student_id from student where student_id in(
select student_id from student_assignments where assignment_id=1 and marks=@highest_marks);

University Database Management System

V.

Research projects having maximum number of students

set @max_stud=(select count(research_id) from research_project_student group by research_id order by count(research_id)


desc limit 1,1);
select * from research_projects where research_id in (
select research_id from research_project_student group by research_id having count(research_id)=@max_stud
);
select @max_stud;

VI.

VII.

Give list of total funding of all research projects

List of projects headed by given TA

select Project_Title,Internal_Project_ID from project_topics where internal_project_id in (


select Internal_Project_ID from ta_internal_project
where ta_id in (select TA_ID from ta_sem_offering where TA_Roll in
(select TA_ID from teaching_assistants where Faculty_ID =
(select Faculty_ID from faculty where Name='Jaina Mehta'))));

University Database Management System

VIII.

10

Student With highest attendance in the given course

set @max_attendence= (select attendence from student_section_course_struct where course_section_id=5


order by attendence desc limit 0,1);
select * from student where Student_ID in(select distinct student_id from student_section_course_struct
where course_section_id=5
and
attendence = @max_attendence);

IX.

Average Attendance(in %age) of the Student in all the courses he has taken so far

set @total_attendance=(select count(*) from student_section_course_struct where student_Id='1301001A01')*10;


set @gained_attendance=(select sum(attendence) from student_section_course_struct where
student_Id='1301001A01');

University Database Management System

set @average_attendance=@gained_attendance*100/@total_attendance;
select @average_attendance as 'Average Attendance(%age)';

X.

Average Attendance of all the students in a given course:

set @total_attendance=(select count(*) from student_section_course_struct where course_section_id=1)*10;


set @gained_attendance=(select sum(Attendence) from student_section_course_struct where course_section_id=1);
set @average_attendance=@gained_attendance*100/@total_attendance;
select @average_attendance as 'Average Attendance(%age)';

XI.

List of Courses Studied by a given student

select course_structure_id,courses.course_id, course_name,credits,lecture_no from course_structure,courses


where course_structure_id in(
select course_structure_id from section_course_structure where course_section_id in(
select course_section_id from student_section_course_struct where student_id='1301001A01'))
and courses.course_id=course_structure.course_id order by course_structure_id;

11

University Database Management System

XII.

List of Courses ordered by their credits and lectures.

select course_structure_id,courses.course_id,course_name,credits,lecture_no,Attendence
from courses,course_structure where courses.course_ID=course_structure.course_ID
order by credits desc,lecture_no desc,Attendence desc;

XIII.

Average Attendance of students of Students for same course in two different section

12

University Database Management System

13

set @total_attendance_sect1=(select count(*) from student_section_course_struct where course_section_id=1)*10;


set @gained_attendance_sect1=(select sum(Attendence) from student_section_course_struct where course_section_id=1);
set @average_attendance_sect1=@gained_attendance_sect1*100/@total_attendance_sect1;
select @average_attendance_sect1 as 'Average Attendance(%age) of Class in Course Section 1';

set @total_attendance_sect13=(select count(*) from student_section_course_struct where course_section_id=13)*10;


set @gained_attendance_sect13=(select sum(Attendence) from student_section_course_struct where course_section_id=13);
set @average_attendance_sect13=@gained_attendance_sect13*100/@total_attendance_sect13;
select @average_attendance_sect13 as 'Average Attendance(%age) of Class in Course Section 13';

XIV.

All the courses taught by all visiting faculty:

select course_structure_id,course_id from course_structure where course_structure_id in(


select distinct course_structure_id from section_course_structure where course_section_id in(
select course_section_id from faculty_course_structure where faculty_id in(
select faculty_id from faculty where designation ='Visiting')));

University Database Management System

XV.

Exam details for a given course_section_id

select * from exams where exam_id in(


select exam_id from exam_course_structure where course_section_id=1);

XVI.

Name of the courses without any prerequisites requirement

select course_id from courses where course_id not in(


select course_id from prerequisites)

XVII.

Number of courses within each department

select Department_ID,Department_type,count(Course_id) from course_dept,department where dept_id=department_id


group by Department_type;

14

University Database Management System

XVIII.

Number of exams conducted in different classes.

select class_ID,count(class_ID) as 'Exams Conducted' from exams group by class_Id;

XIX.

Name of the topics that contain Law


select Name from topics where name like '%law%';

XX.

select funding_funding_id,max(research_projects_has_funding.amount) from


research_projects_has_funding

15

University Database Management System


XXI.

XXII.

Company paying 400000 in funds

Details of Visiting Faculty

XXIII.

Courses having lectures between 18-20

XXIV.

Faculty teaching Particular Student

XXV.

XXVI.

Getting details about all the firms funding various research projects and their
details

Matching workshop and research topics table on relationship

16

University Database Management System

XXVII.

XXVIII.

XXIX.

Funding organizations ISRO has interests in which of the research topics

Funds for game theory projects

Workshop with maximum duration is for which research project

17

University Database Management System

XXX.

XXXI.

XXXII.

query for retrieving details of faculty taking workshops and also being part of the project

query for finding all the students, faculty and TAs in particular research topics and all the
faculties mentoring the workshops in that particular research topics

Maximum number of assignments for a particular course section ID

XXXIII.

Students as student_author

XXXIV.

Faculty as faculty_author

18

University Database Management System

XXXV.

19

Maximum marks in which assignment by which student

select max(student_assignments.Marks),student.Student_ID,Assignment_ID from


student,student_assignments where student_assignments.Student_ID=student.Student_ID group by
Assignment_ID;

XXXVI.

Maximum marks in which exams

select max(student_exams.Marks) as max_marks,student.Student_ID,student_exams.Exam_ID,exam_type from


student,student_exams,exams where student_exams.Student_ID=student.Student_ID and
exams.Exam_ID=student_exams.Exam_ID group by Exam_ID;

XXXVII.

XXXVIII.

XXXIX.

Maximum marks in which quizzes by which students


select max(student_quiz.Marks) as max_marks,student.Student_ID,Quiz_ID from
student,student_quiz where student_quiz.Student_ID=student.Student_ID group by Quiz_ID;

Faculties as workshop mentors

Core courses
select courses.Course_ID from courses,courses_has_course_type where
courses.Course_ID=courses_has_course_type.Course_ID and
courses_has_course_type.Course_type_ID='C';

XL.

XLI.

Information about a particular student attending current courses, faculties those teaching those
courses, attendence of student in all those courses:

Research projects that are completed, funding organizations that funded them, faculties associated with those
projects, T.As associated with those projects, faculties that are associated are teaching which courses and
student attending those course:

University Database Management System

XLII.

XLIII.

List of assignments and its link given for currently taught courses by faculties.

information about number of students living at particular places:

20

University Database Management System

XLIV.

XLV.

Information about as number of faculties assigned particular designation:

list of quizzes associated with different courses and TAs associated with them:

select distinct q.Quiz_ID, q.Date, q.TA_ID, off.TA_Roll, cq.Course_Section_ID, scs.Course_Structure_ID,


cs.Course_ID, c.Course_name
from quizzes q inner join ta_sem_offering off on q.TA_ID = off.TA_ID
inner join course_quiz cq on q.Quiz_ID = cq.Quiz_ID
inner join section_course_structure scs on cq.Course_Section_ID = scs.Course_Section_ID
inner join course_structure cs on scs.Course_Structure_ID = cs.Course_Structure_ID
inner join courses c on cs.Course_ID = c.Course_ID
where q.TA_ID != 0
order by q.ta_id

XLVI.

Number of workshops for given research topic (name)

21

University Database Management System

22

select count(Workshop_ID) as 'Number of Workshops' from workshops_research_topic where R_Topic_ID


in (select R_Topic_ID from research_topics where title = 'Game Theory');

XLVII.

Group faculty in order of the number of classes they take

select faculty.Faculty_ID ,name, count(*) Number_of_classes from faculty_course_structure,faculty


where faculty.Faculty_ID=faculty_course_structure.Faculty_Id group by Faculty_ID order by Number_of_Classes desc;

XLVIII.

List all course IDs having given topic

select Course_ID,Course_Name,Name Topic_Name from courses,topics where course_id in


(select course_id from course_structure where Course_Structure_ID in
(select Course_Structure_ID from course_topics where course_topics.Topic_ID = (select Topic_ID from topics where Name =
'Pointers')))
and name = 'Pointers';

XLIX.

Elective course having maximum student given Section ID

select count(Student_ID) as 'No of Students' from student_section_course_struct where Course_Section_ID in


(select Course_Section_ID from section_course_structure where Course_Structure_ID in
(select Course_Structure_ID from course_structure where Course_ID in
(select Course_ID from course_dept where Elective = 0))
and Section_ID = 1);

L.

Given class id give workshop details

select mentor_id,name,existing_organization,workshop_id,title,start_date,end_date from


visiting_mentor,workshops_has_mentor,Workshops
where mentor_id=mentor_mentor_id and Workshops_Workshop_ID=workshop_id and Workshops_Workshop_ID in
(select distinct Workshops_Workshop_ID from workshops_has_class where Class_Class_ID=101);

LI.

No of Assignments in given course and in given section

select count(*) as No_of_Assignments from assignments natural join assignment_course_structure where Course_Section_ID
in (select Course_Section_ID from section_course_structure natural join course_structure where Course_ID = 'CS101'
and Section_ID = '1' );

LII.

No of Quizzes in given course and in given section

select count(*) as No_of_Quizzes from quizzes natural join course_quiz where Course_Section_ID
in (select Course_Section_ID from section_course_structure natural join course_structure where
Course_ID = 'CS101' and Section_ID = '1' );

LIII.

List of successful research projects


select Research_ID, Title from research_projects where status = 'Completed';

LIV.

Schedule of Exams in given course and in given section

University Database Management System

select Exam_ID,exam_type,Date,Class_ID from exams natural join exam_course_structure where


Course_Section_ID
in (select Course_Section_ID from section_course_structure natural join course_structure where
Course_ID = 'CS101' and Section_ID = '1' );

LV.

Total no of students in university

select count(Student_ID) Total_No_of_Students from dept_student as ds where


Department_ID=ds.Department_ID;

7. Database Programming:

a. Stored Procedures
i. Stored procedure 1, for finding out all the quizzes, assignments and exams on a particular date
-- --------------------------------------------------------------------------------- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- -------------------------------------------------------------------------------DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `reviews_today`(in given_date date)
BEGIN
select
R.Section_ID,
R.Course_ID,
S.Quiz_ID as review_ID,
S.Date,
'QUIZ' as type,
null as exam_type
from
(select
section_course_structure.Section_ID,
course_structure.Course_ID,
section_course_structure.Course_Section_ID
from
course_structure, section_course_structure
where
section_course_structure.Course_Structure_ID = course_structure.Course_Structure_ID) as R,
(select
quizzes.Quiz_ID, quizzes.Date, course_quiz.Course_Section_ID
from
quizzes, course_quiz
where
course_quiz.Quiz_ID = quizzes.Quiz_ID
and quizzes.Date = given_date) as S
where
R.Course_Section_ID = S.Course_Section_ID
union select
R.Section_ID,
R.Course_ID,
S.Exam_ID as review_ID,
S.Date,
'EXAM' as type,
S.exam_type as exam_type
from
(select
section_course_structure.Section_ID,

23

University Database Management System


course_structure.Course_ID,
section_course_structure.Course_Section_ID
from
course_structure, section_course_structure
where
section_course_structure.Course_Structure_ID = course_structure.Course_Structure_ID) as R,
(select
exams.Exam_ID,
exams.Date,
exam_course_structure.Course_Section_ID,
exams.exam_type
from
exams, exam_course_structure
where
exam_course_structure.Exam_ID = exams.Exam_ID
and exams.Date = given_date) as S
where
R.Course_Section_ID = S.Course_Section_ID
union select
R.Section_ID,
R.Course_ID,
S.Assignment_ID as review_ID,
S.Date,
'ASSIGNMENT' as type,
null as exam_type
from
(select
section_course_structure.Section_ID,
course_structure.Course_ID,
section_course_structure.Course_Section_ID
from
course_structure, section_course_structure
where
section_course_structure.Course_Structure_ID = course_structure.Course_Structure_ID) as R,
(select
assignments.Assignment_ID,
assignments.Date,
assignment_course_structure.Course_Section_ID
from
assignments, assignment_course_structure
where
assignment_course_structure.Assignment_ID = assignments.Assignment_ID
and assignments.Date = given_date) as S
where
R.Course_Section_ID = S.Course_Section_ID;
END
OUTPUT
call reviews_today('2013-08-03');

call reviews_today('2013-09-25');

24

University Database Management System

25

ii. Stored procedure 2 : Finding Upcoming quizzes


-- --------------------------------------------------------------------------------- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- -------------------------------------------------------------------------------DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `future_quizzes`(in course_name varchar(10),in sect_id int,in
given_date date)
BEGIN
select quiz_id
from quizzes
where date > given_date
and quiz_id in ( select quiz_id
from course_quiz
where course_section_id = (select course_section_id
from section_course_structure
where section_id=sect_id
and course_structure_id in (select course_structure_id
from
course_structure
where
course_Id=course_name)));
END

call future_quiz('CS101',1,2013-01-01);

iii. Stored procedure 3 : Finding Upcoming workshops


-- --------------------------------------------------------------------------------- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- -------------------------------------------------------------------------------DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `upcoming_workshops_2`(in topic_name varchar(50), in
give_date date)
BEGIN
select *
from workshops
where date(workshops.Start_date)>date(give_date)
and workshops.Workshop_ID in ( select Workshop_ID
from workshops_research_topic
where workshops_research_topic.R_Topic_ID = (select R_topic_ID
from research_topics
where title=topic_name));
END
call upcoming_workshops_2('Communications',2013-01-01);

iv. List of Future Quizzes for a given Course within a given


Section and after given Date

University Database Management System

Output:

v. Attendance of a given Student in given course

Output:

b. Triggers:
i.New Attendance should be greater than the old otherwise the old value is retained:
CREATE DEFINER=`root`@`localhost` TRIGGER `mydb`.`student_section_course_struct_BEFORE_UPDATE` BEFORE
UPDATE ON `student_section_course_struct` FOR EACH ROW
IF NEW.Attendence < OLD.Attendence THEN

26

University Database Management System

27

SET NEW.Attendence = OLD.Attendence;


ELSEIF NEW.Attendence > OLD.Attendence THEN
SET NEW.Attendence = NEW.Attendence;
END IF
ii. Marks cant be greater than maximum and cant be less than 0:
CREATE DEFINER = CURRENT_USER TRIGGER `mydb`.`student_exams_BEFORE_INSERT` BEFORE INSERT ON
`student_exams` FOR EACH ROW
IF NEW.Marks < 0 THEN
SET NEW.Marks = 0;
ELSEIF NEW.Marks > 50 THEN
SET NEW.Marks = 50;
END IF
iii. Before Deleting Department, delete that department record from Dept_Prog Table:
CREATE DEFINER = CURRENT_USER TRIGGER `mydb`.`department_BEFORE_DELETE` BEFORE DELETE ON
`department` FOR EACH ROW
delete from dept_prog where Department_ID=old.Department_ID
iv. After insert into grade_points revert the change
CREATE DEFINER=`root`@`localhost` TRIGGER `mydb`.`grade_points_AFTER_INSERT` AFTER INSERT ON `grade_points`
FOR EACH ROW
begin
delete from grade_points where Grade=NEW.Grade;
end

v. After update grade_points revert the change


CREATE DEFINER=`root`@`localhost` TRIGGER `mydb`.`grade_points_AFTER_UPDATE` AFTER UPDATE ON `grade_points`
FOR EACH ROW
begin
update grade_points set Grade=OLD.Grade where Grade=NEW.Grade;
update grade_points set Grade_Point=OLD.Grade_Point where Grade_Point=NEW.Grade_Point;
end

vi. After delete restore deleted values


CREATE DEFINER=`root`@`localhost` TRIGGER `mydb`.`grade_points_AFTER_DELETE` AFTER DELETE ON `grade_points`
FOR EACH ROW
begin
insert into grade_points values (OLD.Grade,OLD.Grade_point);
end

c. Java Connected Table

8. References
a. http://stackoverflow.com/
b. http://dba.stackexchange.com/
c. http://www.w3schools.com/sql/

University Database Management System


d. http://dev.mysql.com/doc/refman/5.0/en/

28

You might also like