1 CREATE TRIGGER upd_topics AFTER INSERT ON messages
2 FOR EACH ROW UPDATE topics SET
3 lastpost = NEW.messageid,
4 posts = (SELECT COUNT(messageid) FROM messages WHERE topicid = NEW.topicid)
5 WHERE topics.topicid = NEW.topicid;
7 CREATE TRIGGER upd_boardposts AFTER UPDATE ON topics
8 FOR EACH ROW UPDATE boards SET
9 posts = (SELECT SUM(posts) FROM topics WHERE boardid = NEW.boardid)
10 WHERE boards.boardid = NEW.boardid;
12 CREATE TRIGGER upd_boardtopics AFTER INSERT ON topics
13 FOR EACH ROW UPDATE boards SET
14 topics = (SELECT COUNT(*) FROM topics WHERE boardid = NEW.boardid)
15 WHERE boards.boardid = NEW.boardid;