MySQL中的触发器insert、update

阅读更多

以下为MySQL 触发器insert 的3个示例演示(update类似)

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 ; 

 

http://database.51cto.com/art/201006/203942.htm

你可能感兴趣的:(MySQL,触发器)