2013-08-29 57 views

回答

1

你在找?

DELIMITER $$ 
CREATE TRIGGER tg_ai_article_votes 
AFTER INSERT ON article_votes 
FOR EACH ROW 
BEGIN 
    UPDATE articles 
    SET votes = COALESCE(votes, 0) + 1 
    WHERE id = NEW.article_id; 
    UPDATE members 
    SET points = COALESCE(points, 0) + 1, 
     lifetime_points = COALESCE(lifetime_points, 0) + 1 
    WHERE id = NEW.member_id; 
END$$ 

CREATE TRIGGER tg_ad_article_votes 
AFTER DELETE ON article_votes 
FOR EACH ROW 
BEGIN 
    UPDATE articles 
    SET votes = COALESCE(votes, 0) - 1 
    WHERE id = OLD.article_id; 
    UPDATE members 
    SET points = COALESCE(points, 0) - 1, 
     lifetime_points = COALESCE(lifetime_points, 0) - 1 
    WHERE id = OLD.member_id; 
END$$ 
DELIMITER ; 

這裏是SQLFiddle演示

+0

是的,它沒有 - 我剛剛到現在 - 謝謝你對我的幫助。 – Padraig

+0

@Padraig您絕對值得歡迎。祝你好運 :) – peterm

相關問題