日期:2014-05-18 浏览次数:20576 次
proadd.asp的主要代码如下:
on error resume next
conn.BeginTrans
for i =1 to 10
    pid=request.form("proid"&i)
    num=request.form("num"&i)
    sql="insert into prolist(pid,account) values('"&pid&"','"&num&"')"
    conn.execute(sql)
end if
if conn.Errors.Count=0 then
    conn.CommitTrans
    response.write "成功更新。"
else
    conn.RollbackTrans
    call alert("执行操作时出错,请重新尝试!")
end if
-------------------------------------------------
ms sql2000中,表prolist的字段如下:用于记得每次进仓,出仓的明细记录的:
id    pid(即是产品ID号)    account
--------------------------------------------------
库存表proall的字段如下:
pid   allaccount
--------------------------------------------------
我想要个触发器,实现每次向表prolist插入数据时,将通过prolist的触发器将数量account累加到proall表中。
如果程序文件proadd.asp不是用事务的话,触发器大伙都知怎么编写的,就如下:
CREATE TRIGGER [prolist_add] ON dbo.prolist 
FOR INSERT 
AS
begin
    declare @pid numeric(10)
    declare @account numeric(10)
    select @pid=pid,@account=account from inserted
    update proall set allaccount=allaccount + @account where pid=@pid
end
我想问的是,程序文件proadd.asp用了事务的话,上面这个触发器就只会最后一次insert记录进行更新,
而前面的是没有更新表proall的allaccount的,
那请问,这个触发器怎么写呢?在线等。。。。。。。