gpt4 book ai didi

mysql - 我想在 mysql 中创建一个触发器,当更新另一个表中的行时,它会在表中插入一行

转载 作者:行者123 更新时间:2023-11-29 11:42:14 25 4
gpt4 key购买 nike

我想在mysql中创建一个触发器,当另一个表event_data中有任何更新(如果event_data.title='event_media')时,它会在表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 ;

最佳答案

我认为这应该可行。请尝试一下。

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

关于mysql - 我想在 mysql 中创建一个触发器,当更新另一个表中的行时,它会在表中插入一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35577352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com