Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger update another table's counter
- DROP TRIGGER IF EXISTS trigger_votes;
- CREATE TRIGGER trigger_votes AFTER INSERT ON votes
- UPDATE collections
- SET IF(vote = 1, loves, hates) = IF(vote = 1, loves, hates) + 1
- WHERE collections.id = NEW.collection_id;
- DELIMITER $$
- CREATE TRIGGER trigger_votes AFTER INSERT ON votes FOR EACH ROW
- BEGIN
- UPDATE collections
- SET loves = CASE NEW.vote WHEN 1 THEN loves + 1 ELSE loves END
- ,hates = CASE NEW.vote WHEN 1 THEN hates ELSE hates + 1 END
- WHERE collections.id = NEW.collection_id;
- END $$
- DELIMITER ;
Add Comment
Please, Sign In to add comment