i'm trying to create a trigger but there is an error somewhere and since i'm new at this i can't solve it...
So basically i have two tables:
students(stud_num:INT, grade_avg :real)
grading(stud_num:INT, classe:char(5), grade:int)
in students stud_num is the primary key, and in grading it references the table students..
What my professor wants is for me to create a trigger that every time we insert a grade in grading, the grade_avg is updated in students.
This is what i have so far:
DELIMITER %%
CREATE TRIGGER something
AFTER INSERT ON grading
FOR EACH ROW BEGIN
@stud_num=new.stud_num;
UPDATE students
SET grade_avg=(SELECT AVG(grade) FROM grading WHERE stud_num=@stud_num);
END;
%%
Can someone please help me?