欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MySQL中的触发器insert、update

程序员文章站 2022-05-08 21:10:56
...

以下为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 触发器