我想在mysql中创建一个触发器,如果event_data.title ='event_media',当另一个表event_data中有任何更新时,会在表change_history中插入一行。
DELIMITER $$
CREATE TRIGGER `after_evdata_update`
AFTER UPDATE ON event_data
FOR EACH ROW
BEGIN
if OLD.title <=> 'event_media'
INSERT INTO change_history (badge,city,country,venue,company,
date,rehosted,type,cancelled,name,tagline,description,agenda,pricing,
edition,photo_video,exhibitors,speakers,official_url,twitter_handle,
twitter_hashtag,facebook_url,contact,post_review_id) values(1,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,null);
end if;
END $$
DELIMITER ;
答案 0 :(得分:1)
我认为这应该有效。请试试。
BEGIN
IF (OLD.title <> 'event_media')
THEN
INSERT INTO `change_history` (`xxx_id`,`and_all_other_fields_similar_way`)
VALUES (old.xxx_id,old.and_all_other_fields_similar_way);
END IF;
END