CREATE TRIGGER `after_customer_insert`
AFTER INSERT ON `customer`
FOR EACH ROW BEGIN
UPDATE `user`
SET
`customers_count` = `customers_count` + 1
WHERE `id` = NEW.`user_id`;
END$$
与其调用UPDATE user
中的每个新行customer
,不如将触发器作为一个“整体”?我的意思是
CREATE TRIGGER `after_customer_insert`
AFTER INSERT ON `customer`
BEGIN
UPDATE `user`
SET
`customers_count` = (
SELECT COUNT(`id`)
FROM `customer`
WHERE `user_id` = `id`
)
END$$