Arsen
Arsen

Reputation: 21

How execute a trigger SQL by condition?

I need execute a trigger INSERT after adding row at table subscrubetousers with a condition:

subscrubetousers.SubscrubeToUsersType = 9

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

Upvotes: 0

Views: 65

Answers (1)

Ivan Cachicatari
Ivan Cachicatari

Reputation: 4284

Just add a condition to your trigger body:

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

Upvotes: 2

Related Questions