Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Lab06-Procedimientos-y-triggers2/procedures.sql
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (31 sloc)
808 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- RF-006 | |
DELIMITER // | |
CREATE OR REPLACE PROCEDURE procDeleteGrades(studentDni CHAR(9)) | |
BEGIN | |
DECLARE id INT; | |
SET id = (SELECT studentId FROM Students WHERE dni=studentDni); | |
DELETE FROM Grades WHERE studentId=id; | |
END // | |
DELIMITER ; | |
DELIMITER // | |
CREATE OR REPLACE PROCEDURE procDeleteData() | |
BEGIN | |
DELETE FROM Grades; | |
DELETE FROM GroupsStudents; | |
DELETE FROM Students; | |
DELETE FROM Groups; | |
DELETE FROM Subjects; | |
DELETE FROM Degrees; | |
END // | |
DELIMITER ; | |
-- CALL procDeleteGrades('12345678A'); | |
CALL procDeleteData(); | |
DELIMITER // | |
CREATE OR REPLACE FUNCTION avgGrade(studentId INT) RETURNS DOUBLE | |
BEGIN | |
DECLARE avgStudentGrade DOUBLE; | |
SET avgStudentGrade = (SELECT AVG(value) FROM Grades | |
WHERE Grades.studentId = studentId); | |
RETURN avgStudentGrade; | |
END // | |
DELIMITER ; |