我在MySql中遇到TRIGGER問題。基於查詢刪除特定記錄的簡單TRIGGER
notifications_posts
notification_id from_user on_post_id in_group_id date
2 1 162 3 2012-07-11 12:01:08
3 19 163 1 2012-07-11 12:03:26
4 19 164 1 2012-08-10 17:42:36
5 1 165 3 2012-08-29 12:14:01
6 1 165 3 2012-08-29 12:14:29
11 1 2 3 2012-08-29 14:38:42
有時我需要刪除的帖子,例如使用下面的命令:
DELETE FROM posts WHERE posts.post_id = 165;
在這之後,我想的是,根據該ID從notification_id
將刪除所有記錄的觸發器。
這是我到目前爲止有:
DELIMITER $$
CREATE OR REPLACE TRIGGER CleanNotificationPosts
AFTER DELETE ON posts
FOR EACH ROW
BEGIN
DELETE FROM notifications_posts WHERE notifications_posts.id = THAT_ID_TO_DELETE;
END $$
DELIMITER ;
是我的語法是否正確?我真的需要分隔符嗎?
是否有問題,或者是修改代碼? –