You are on page 1of 7

Stored Procedures - Practice

1
EduBD

student(student_id, first_name, last_name, dob, gender, address, note, class_id)

subject(subject_id, name, credit, percentage_final_exam)

lecturer(lecturer_id, first_name, last_name, dob, gender, address, email)

teaching(subject_id, lecturer_id)

grade(code, fromScore, toScore)

clazz(clazz_id, name, lecturer_id, monitor_id)

enrollment(student_id, subject_id, semester, midterm_score, final_score)

2
EduBD

3
Define a function
1) Given a classID, write a function, named :
number_of_students, that calculates the number of students
in this class.

 Try to call this function from superuser account

4
Execute a function with normal role
 Define an user role named : joe; pass: 12345678

 Login with joe account ➔execute the function


number_of_students(a_class_id)

 Login with superuser => Grant execute privilege on this


function to joe

 Login with joe account => Re-execute the function


number_of_students(a_class_id)
5
Exercices
2) Add a new attribute (named: number_students, data type: integer) on
clazz table to store number of students in class.

 Define a function (named update_number_students()) that computes


the number of students for each class and update the correct value
for number_students attribute.

 Check values in this attribute before and after calling the function
update_number_students()

6
Exercices
3) Create a new table to store GPA (float), CPA (float) of students in
each semester
student_results(student_id, semester, GPA, CPA)
 Define a function to update GPA, GPA of a student in a semester.
Student_id and semester are input variables ot the function
updateGPA_student(studentid, semester)
 Define a function to update GPA, GPA for all students in the semester
indicated by a input variable.
updateGPA(semester)
 Check whether your functions work correctly or not

You might also like