create trigger instb on sc_stocks
for insert as
update kclb
set 库存数量=k.库存数量+i.数量*m.类型
from stockM m,inserted i,kclb k
where i.partid=k.partid
and m.djid=i.djid
for insert as
update kclb
set 库存数量=k.库存数量+i.数量*m.类型
from stockM m,inserted i,kclb k
where i.partid=k.partid
and m.djid=i.djid
解决方案 »
- 关于项目上线前的数据清洗,请各位过来看看,或许对你也有用哦
- 请教一个sql语句
- SQL Server已为8个并发查询而优化。15 个查询超过了此限制...
- 请教一个关于交叉表的问题 (继续深入)
- 哪里有下载SQLSERVER 2000 64BIT英文版的?
- 关于sp3,网络不稳定是不是sql 蠕虫病毒引起?
- 为什么我改了我的windows2000server的管理员密码后,重新登陆后,登陆sqlserver就失败?
- 我装sql2000出现问题了,大家帮忙!
- 巨难的问题.....相信大家都可能会遇到, 将打竖的数据变成打横的数据的问题
- sql2008 恢复模式:完整 事务日志已满问题
- 备份数据库
- 在存储过程中如何判断语句是否正常执行?
insert,update
as
begin
update kcl set 数量=数量+sotcks.数量*stockM.类型 from stockM,stocks,inserted where stockM.djid=stocks.djid and stocks.产品=kcl.产品
create trigger tri_ttt on stocks for
insert,update
as
begin
update kcl set 数量=数量+sotcks.数量*stockM.类型 from stockM,stocks,klb,inserted where stockM.djid=stocks.djid and stocks.产品=kcl.产品 and stocks.产品=inserted.产品
for
insert,update
as
update kclb
set
库存数量=K.库存数量+I.数量*M.类型
from stockM m,STOCKS i,kclb k
where i.partid=k.partid
and m.djid=i.djid
for
insert,update
as
update kclb
set
库存数量=K.库存数量+I.数量*M.类型
from stockM m,STOCKS i,kclb k
where i.partid=k.partid
and m.djid=i.djid
我试过 Yang_(扬帆破浪)的那个触发器能成功的!
我试用了 Yang_(扬帆破浪) 给的那个,已成功了!
j9988(j9988) 给的那个触发器也能成功,再次感谢!
我准备结贴给分了!!听说触发器占资源很大?是否属实?
呵呵,我现在感觉行了,还没看出问题?要是删除、或更新一个stockS的记录!是否要另写多一个TRIGGER?
create trigger instb on sc_stocks
for insert as select i.partid,sum(i.数量*m.类型) as 数量 into #Temp from inserted i,stockM m
where m.djid=i.djid
group by i.partidupdate kclb
set 库存数量=k.库存数量+t.数量
from #Temp t,kclb k
where t.partid=k.partid insert kclb(partid,库存数量)
select partid,数量 from #Temp t
where not exists (
select * from kclb k
where k.partid=t.partid
)
go