Reputation: 45
I've tried to create trigger for each new post here is my code
CREATE TRIGGER insertprod AFTER INSERT ON post
FOR EACH ROW
BEGIN
INSERT INTO attributes SET attrtext = 'sometext', post_id = NEW.id;
END;
I'm getting this error
Upvotes: 0
Views: 63
Reputation: 1269445
You probably just need a delimiter:
DELIMITER $$
CREATE TRIGGER insertprod AFTER INSERT ON post
FOR EACH ROW
BEGIN
INSERT INTO attributes SET attrtext = 'sometext', post_id = NEW.id;
END;
$$
DELIMITER ;
However, you are also using a non-standard form of INSERT
. I would suggest:
DELIMITER $$
CREATE TRIGGER insertprod AFTER INSERT ON post
FOR EACH ROW
BEGIN
INSERT INTO attributes(attrtext, post_id)
VALUES('sometext', NEW.id);
END;
$$
DELIMITER ;
Upvotes: 2
Reputation: 592
Your INSERT command is wrong. It should have been
INSERT INTO attributes (attrtext, post_id) VALUES ('sometext', NEW.id);
Upvotes: 0
Reputation: 1303
The parser is confused by the ;
that terminates the statement inside the trigger's BEGIN...END
block. You need to use a DELIMITER
statement to define a new delimiter, which you can then use to end the CREATE TRIGGER
statement.
Upvotes: 0