如何按条件执行触发器SQL?

时间:2014-10-13 16:02:47

标签: mysql sql

我需要在表 subscrubetousers 的行添加一个条件后执行触发器 INSERT

subscrubetousers.SubscrubeToUsersType = 9

BEGIN
   INSERT INTO logsub Set 
   LogTime = NEW.subscrubetousersTime, 
   LogIdNote = NEW.subscrubetousersId, 
   LogType = NEW.SubscrubeToUsersType;
END

1 个答案:

答案 0 :(得分:2)

只需在触发器主体中添加一个条件:

BEGIN
   IF NEW.SubscrubeToUsersType = 9 THEN
       INSERT INTO logsub (LogTime,LogIdNote,LogType) 
       VALUES (NEW.subscrubetousersTime, NEW.subscrubetousersId,NEW.SubscrubeToUsersType);
    END IF;
END