Issue
I'm trying to create a trigger using Phpmyadmin, but my trigger keeps getting rejected.
Suppose having these tables:
News (Code, etc.)
Student (Code, etc.)
Teacher (Code, etc.)
Courses (Code, etc.)
NewsList (NewsCode, TeacherCode, CourseCode)
StudsCoursesList (StudentCode, CourseCode)
etc., but these are the ones I'm using in this trigger.
Here's the code:
DELIMITER //
CREATE TRIGGER newNews
AFTER INSERT
ON News FOR EACH ROW
BEGIN
SET @news = (SELECT MAX(Code) FROM News);
SET @course = (SELECT CourseCode FROM NewsList WHERE NewsCode=@news);
SET @cod = (SELECT TeacherCode FROM NewsList WHERE NewsCode=@news);
SET @studs = (SELECT StudentCode FROM StudsCoursesList WHERE Course=@course);
SET @i = 0;
WHILE @i < COUNT(@studs)
{
INSERT INTO Inbox(Sender, Receiver, Object, Content, Date) VALUES (@cod, @i, @studs[i], "", CURDATE());
i++;
}
END; //
DELIMITER ;
Phpmyadmin shows this message:
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 '{
INSERT INTO Inbox(Sender, Receiver, Object, Content, Date) VALUES (' at line 12
I don't understand what is the problem. Before pointing out that Date might get a conflict, it's just translated in english, in my language I use Data.
Solution
Sorry, but MySQL syntax doesn't have curly braces and your WHILE is missing the DO.
Change your WHILE loop to
WHILE @i < COUNT(@studs) DO
INSERT INTO Inbox(Sender, Receiver, Object, Content, Date) VALUES (@cod, @i, @studs[i], "", CURDATE());
@i = @i + 1;
END WHILE; //
Answered By - Sarath Chandra
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.