Answer the question
In order to leave comments, you need to log in
Why doesn't the MYSQL trigger fire?
There are the following tables:
users
id, discount, ...
coupons
id, code, ...
discounts
id, user_id, discount, ...
ALTER TABLE `discounts`
ADD CONSTRAINT `discounts_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
CREATE TRIGGER `after_delete_discounts` AFTER DELETE ON `discounts`
FOR EACH ROW BEGIN
UPDATE `users` SET `discount` = (SELECT SUM(`discount`) FROM `discounts` WHERE `user_id` = `OLD`.`user_id`) WHERE `id` = `OLD`.`user_id` LIMIT 1;
END
Answer the question
In order to leave comments, you need to log in
From documentation :
Triggers are not activated by foreign key actions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question