0% found this document useful (0 votes)
18 views

Stored Procedures - Practice

The document discusses stored procedures in practice and provides examples of defining functions to retrieve student data from educational databases like calculating the number of students in a class, updating the student count in classes, and updating student GPA and CPA values for a given semester.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Stored Procedures - Practice

The document discusses stored procedures in practice and provides examples of defining functions to retrieve student data from educational databases like calculating the number of students in a class, updating the student count in classes, and updating student GPA and CPA values for a given semester.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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