I have an error while executing this query:
CREATE TRIGGER insert_Topics
BEFORE INSERT
ON Topics
FOR EACH ROW
BEGIN
IF (SELECT COUNT(*) FROM Subjects WHERE ID=new.SubjectID)=0
THEN
INSERT error_msg VALUES ('Foreign Key Constraint Violated!');
END IF;
END;
delimiter ;
The error says:
1064 – 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 8
and it points to the word THEN
Any help? Thanks in advance.
Both
and
work for me, so your syntax problems probably lie elsewhere.