gpt4 book ai didi

mysql - 如何在触发器中添加条件?

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

我有关于crete触发器的查询:

CREATE TRIGGER `Insert` AFTER INSERT ON `HistoryBalance`
FOR EACH ROW INSERT INTO Winners (name) VALUES (new.ProductID)

但现在我想获取条件:

if (new.Status = 'user'){
CREATE TRIGGER `Insert` AFTER INSERT ON `Balance`
FOR EACH ROW INSERT INTO Winners (name) VALUES (new.ProductID)
}

请告诉我 crete 触发器如何适合我的情况?

最佳答案

你可以这样做:

delimiter $$
CREATE TRIGGER balance_insert AFTER INSERT ON Balance
FOR EACH ROW
BEGIN
if (new.Status = 'user') then
INSERT INTO Winners(name) VALUES (new.ProductID);
end if;
END; $$
delimiter ;

您可以阅读更多Here

关于mysql - 如何在触发器中添加条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26580145/

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