我正在尝试为更新查询创建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)
);
我的问题是触发器正在创建,但是插入器查询不起作用。这意味着在运行更新查询后,数据不会插入到
access_log
表中。希望有人可以帮助我。
最佳答案
INSERT INTO access_log (id,action,previous_data,current_data)
该行包含4个字段
在下面,您将提供6
关于mysql - 更新后的MySQL触发器问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34061549/