msql 触发器
#create trigger 触发器名 触发时机 触发事件 on 表名 for each row
#在USER表插入一行数据的时候,将表中的id字段中最大值的行插入path表中
create trigger tri1 after insert on `user` for each row
BEGIN
#取得id字段的最大值 并存入变量@max1
select max(id) into @max1 from `user`;
select `user` into @user1 from `user` where id = @max1;
SELECT pwd into @pwd1 from `user` where id = @max1;
insert into path(type,`name`) values(@user1,@pwd1);
end;
#在user插入数据之前,将该行的数据也插入到一个跟其类似结果的表中
create trigger tri2 before insert on `user` for each ROW
BEGIN
set @v1 = new.user;
set @v2 = new.pwd;
insert into type(id,name) values(@v1,@v2);
end;