I have a forum site running and want to update the number of comments added to each post. This MUST be done by trigger and i was thinking of having it like this: A comment is submitted and the trigger then takes the id of the original post and updates the column comments in the table Post where the id is the same, by increasing the number already in there. If that makes sense?
CREATE TRIGGER addcomment
AFTER INSERT ON Reply FOR EACH ROW
BEGIN
DECLARE v_postid integer;
SELECT post_id() INTO v_postid FROM dual;
UPDATE Post
SET comments = comments +1
WHERE post_id=v_postid;
END;