写一个触发器,在更新和插入时,一个表中的一个字段等于其中两个字段的和
1个回答
展开全部
create or replace trigger tr_afterupdate
after insert or update
on tablename
for each row
begin
update tablename set score=:new.attackscore+:new.surroundscore where id=:new.id;
end;
追答
我写的是适用于Oracle的SQL,如果是MySQL则应该如下写:
delimiter $
create or replace trigger tr_triggername
after insert or update
on bridge_user_scorerank
for each row
begin
update bridge_user_scorerank set score=NEW.attackscore+NEW.surroundscore where id=NEW.id;
end$
delimiter ;
--下边的写法更好
delimiter $
create or replace trigger tr_triggername
before insert or update
on bridge_user_scorerank
for each row
begin
NEW.score=NEW.attackscore+NEW.surroundscore;
end$
delimiter ;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询