我正在尝试为更新查询创建一个mysql触发器。在这里,我使用单独的更新查询来进行用户更改。
1. personal details
2. address details
3. contact details
所以我需要创建一个触发器来用于所有上述更改。
这是我尝试的方式:
CREATE TRIGGER log_change
AFTER UPDATE ON users
FOR EACH ROW
INSERT INTO access_log (id,action,previous_data,current_data)
VALUES (
NEW.user_id,
CASE
WHEN (NEW.address <> OLD.address) OR
(NEW.city_id <> OLD.city_id)
THEN 'Beneficiary address details'
WHEN (NEW.email <> OLD.email) OR
(NEW.telephone <> OLD.telephone) OR
(NEW.mobile <> OLD.mobile)
THEN 'Beneficiary contact details'
ELSE 'Beneficiary personal details'
END,
CONCAT_WS("<br>\n"
, IF(OLD.title<>NEW.title, CONCAT('Title: ',OLD.title), NULL)
, IF(OLD.beneficiary_name<>NEW.name, CONCAT('Beneficiary Name: ', OLD.name), NULL)
, IF(OLD.gender<>NEW.gender, CONCAT('Gender: ',OLD.gender), NULL)
),
CONCAT_WS("<br>\n"
, IF(OLD.title<>NEW.title, CONCAT('Title: ',NEW.title), NULL)
, IF(OLD.beneficiary_name<>NEW.name, CONCAT('Beneficiary Name: ', NEW.name), NULL)
, IF(OLD.gender<>NEW.gender, CONCAT('Gender: ', NEW.gender), NULL)
),
CONCAT_WS(', ', OLD.address, OLD.city_id),
CONCAT_WS(', ', NEW.address, NEW.city_id)
);
我的问题是触发器正在创建,但是inser查询无效。这意味着在更新查询运行后,数据不会插入access_log
表。
希望有人可以帮助我。
答案 0 :(得分:0)
void
这一行包含4个字段 在下面你提供6