在我的应用程序中,我使用触发器来计算成本并在插入数据时更新成本,但如果在帐单中插入200个项目,则需要2-3分钟来保存。但是如果我删除了触发它只需要不到30秒执行触发器时数据插入太慢
是否可以在不影响应用程序的情况下相互依赖地执行触发器? OR 是否有任何替代办法做到这些?(要带只比30年代少,但成本更新用应该相互依赖工作)
我可以使用线程/ BackgroundWorker的?难道是挂起应用程序时,10个用户做在连续计费一时间
这些是我的触发
SET NOCOUNT ON;
declare @nopqty decimal(10,2)
declare @nminusqty decimal(10,2)
declare @ntotamt decimal(10,2)
declare @nstock decimal(10,2)
declare @ncost decimal(10,2)
declare @qry nvarchar(4000)
declare @norgcd int
declare @npartno nvarchar(20)
set @norgcd = (select orgcd from inserted)
set @npartno = (select docpart from inserted)
set @nopqty=(select oqty101 from stock where [email protected])
set @ntotamt=(select ocost101 from stock where [email protected])
set @nopqty = @nopqty+ (select sum(sellqty) from prtdet where trcd in(select trcd from invtran where qtyadd='+' and lcardx='True') and [email protected] and status1='True' and status2='True' and status3='True' and [email protected])
set @nminusqty = (select sum(sellqty) from prtdet where trcd in(select trcd from invtran where qtyadd='-' and lcardx='True') and [email protected] and status1='True' and status2='True' and status3='True' and [email protected])
set @ntotamt = @ntotamt+ (select sum(tamt) from prtdet where trcd in(select trcd from invtran where qtyadd='+' and lcardx='True') and [email protected] and status1='True' and status2='True' and status3='True' and [email protected])
set @nstock =(@[email protected])
set @ncost =(@ntotamt/@nopqty)
set @qry = 'update stock set cqty'+convert(varchar(3),@norgcd)+'='+convert(nvarchar(12),@nstock)+',ccost'+convert(varchar(3),@norgcd)+'='+convert(nvarchar(12),@ncost)+' where part='''[email protected]+''''
exec sp_executesql @qry
我是在触发小清新和存储过程
我想更新库存成本和stockvalue(加权平均)用于每个更新和项目的插入。任何人都可以告诉我很好的方法来实现这些
您可以在插入记录时添加更多关于触发器实际执行的信息吗?您是一次插入1行还是批量执行此操作?如果您一次只做1行,您可能会遇到延迟/往返问题。除非使用事务来锁定表,否则可以使用backgroundworker。如果您正在使用交易,其他9个用户将无法修改,直到完成第一个交易。 –
我会更感兴趣的是为什么它需要30秒才能在您的良好场景中插入200件物品。 –
触发器可以很好,这取决于你如何编码它。如果你在触发器中有一个游标或一个循环,你需要重写它以使用基于集合的操作,如果你想要任何体面的表现。 –