建立一个inser触发器

功能:

d表有属性(d_id,s_num,sum),yao表有属性(id,price,count)(注:d_id跟ID一样)

当我向d表添加:insert  into d(s_id,num)  values ( '01',6)时,更改yao表中count=count-5,d表的s_sum=price*num,

我的代码为:

delimiter $

create trigger tg1 after insert on d for each row 

begin

update yao,d set count=count-new.num,d_sum=new.num*sprice where id=new.d_id;

end$

delimiter;

结果显示:

Can't update table 'd' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

求大神帮我写个,或者改下




蓝鸟渣渣
浏览 1185回答 2
2回答

侠客岛的含笑

换个名字试试
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL