linux_security
linux_security

Reputation: 25

MySQL trigger insert

I am attempting to increment count in my grade_distribution table whenever a new row is inserted into my Grades table. When the grade inserted into Grades is the same as the grade in grade_distribution, the count should be incremented.

But i am getting an error: ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6

create trigger tr_grades_insert after insert on Grades
for each row
begin 
    update grade_distribution
    set grade_distribution.count = grade_distribution.count+1 
    where Grades.Grade = grade_distribution.grade;
end

Upvotes: 0

Views: 95

Answers (1)

linux_security
linux_security

Reputation: 25

I needed a delimiter to end the trigger. Also to use update students.grade_distribution

DELIMITER //
create trigger tr_grades_insert after insert on Grades
for each row
begin 
    update students.grade_distribution
    set count=count+1 
    where grade = NEW.Grade;
end//
DELIMITER ;

Upvotes: 1

Related Questions