和触发器不同的是,需要制定时间点触发,不能认为调用
注意点:两种场景 before和after
before: 可以对当前行(new)进行修改,修改使用 set 语法(见代码),而不是update sql(会造成循环)
after: 不可以对当前行(new)进行修改(修改会造成死循环)
begin set @uname = ""; set @tname = ""; select username into @uname from member where id = new.uid; if new.type = 1 then select activity_name into @tname from tickets_fixed where id = new.tid; else select activity_name into @tname from tickets_random where id = new.tid; end if; set new.tname = @tname; set new.uname = @uname; end