我现在有个表是多对一的关系表(t2,t1)
共同字段为 id,num
t1(表名)
id num xx yy
t2
id num
现在我要批量向表t2插入数据其中插入的时候我要触发器工作,
where t1.id=t2.id的时候,if(xx>t1.num-t2.num) update t1 set num=t1.num-
t2.num
else
update t1 set num=t1.num-t2.num,yy=不足
一条的时候我可以处理,但是当多条记录一起导入的时候只能更改第一条
后来我用SUM函数来做的时候,可以正确更改num字段,但是我不知道怎么样加入判断条件来控制yy字段.
急需你 的帮助.告诉我怎么样做好吗?
我的qq;17400566
if(xx>t1.num-t2.num)
xx是什么??
create trigger triggername on t2
for insert
as
update t1 set num=a.num-b.num,yy=case when t1.xx>=t2.num then else
不足 end from t1 a,inserted b where a.id=b.id