我觉得你这个还不如不要触发器,你在往里插入数据的时候判断有没有该hp_id的记录,如果有就把它加上product_quantity更新它,如果没有再插入,这样做也降低了维护

解决方案 »

  1.   

    同意楼上的建议:
    declare @hp_id int
    set @hp_id = 2
    if exists select * from total where hp_id = @hp_id
       update total set product_quantity = product_quantity + 2,
                        product_inputdate = '2002-10-21'
                    where hp_id = @hp_id
    else
       insert into total (hp_id,product_quantity,product_unit,    product_inputdate) values (1,2,"台","2002-10-21")