我有查询创建触发器:
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)
}
请告诉我克利特在我的情况下如何正确触发?
答案 0 :(得分:0)
你可以这样做:
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