mysql触发器是mysql数据库的重要概念,下面为您介绍三个mysql触发器的例子,供您参考,希望对您学习mysql触发器方面能有所帮助。
- 示例一
- delimiter //
- create trigger InsertUser
- before insert on user
- for each row
- Begin
- insert into user_group(uid,gid) values(new.uid,'group4444444444');
- end;//
- delimiter ;
- 示例二
- delimiter //
- create trigger InsertUser
- before insert on user
- for each row
- Begin
- IF new.Type=2 then
- insert into user_group(uid,gid) values(new.uid,'group4444444444');
- else
- insert into user_group(uid,gid) values(new.uid,'group55555555555')
- END IF;
- end;//
- delimiter ;
- 示例三:
- delimiter //
- create trigger InsertUser
- before insert on user
- for each row
- Begin
- IF new.type=1 then
- insert into user_group(uid,gid) values(new.uid,'578d3369633b47bd9c1fe8bf905cbfb1');
- END IF;
- IF new.type=2 then
- insert into user_group(uid,gid) values(new.uid,'387bcd57fc5a4c3c9de83ee210fef661');
- END IF;
- end;//
- delimiter ;
【编辑推荐】