顶楼上的
使用触发器来实现
对B表进行Insert和Update动作时,修改A表记录.

解决方案 »

  1.   

    if exists(select * from sysobjects where name = 'A' and xtype = 'U')
    drop table A 
    if exists(select * from sysobjects where name = 'B' and xtype = 'U')
    drop table Bcreate table A(
    id nvarchar(2),
    店名 nvarchar(4),
    日期 datetime,
    応収金額 money,
    実収金額 money
    )
    insert into A values('01','001','2004-12-26 10:54:37.000',10,10) 
    insert into A values('02','001','2004-12-26 11:54:37.000',11,10)
    insert into A values('03','002','2004-12-26 12:54:37.000',12,12)create table B(
    id nvarchar(2),
    商品编码 nvarchar(4),
    销售数量 int,
    销售价 money,
    实收金额 money
    )
    insert into B values('01','1001',1,10,10) 
    insert into B values('02','1002',1,5.5,5.5)
    insert into B values('02','1003',1,5.5,5.5)
    insert into B values('03','1004',1,12,12)if exists(select * from sysobjects where name = 'dd' and xtype = 'tr')
    drop trigger dd
    go
    create trigger dd on B for delete
    as
    declare @id nvarchar(2),@money1 money,@money2 money
    select @id = id from deleted
    select @money1 = 销售价 from deleted
    select @money2 = 实收金额 from deleted print @id
    print @money1
    print @money2 update A
    set 応収金額 = 応収金額 - @money1,実収金額 = 実収金額 - @money2
    where A.id = @id
    go
    --test date
    select * from A
    delete from B where 商品编码 = '1003'
    select * from A
      

  2.   

    我现在还想加一个条件.表C  记录的是商品信息明细表.
    商品编码   商品名  规格       供应商
    10001      式      X        001
    10002       小     M        006
    10003       大     I        001
    10004       中     W        002把供应商编码为:001的销售记录全部删除
      

  3.   

    这个表C的做法跟表B的做法其实一个道理的,只要能看懂上面表B的操作,这个问题就很简单了
    自己动手,丰衣足食啊,别太懒了
      

  4.   

     delete b where 商品编码 in ( select 商品编码 from c where 供货商=001)
      

  5.   

    DELETE t_sale_d 
    FROM t_sale_d   Left Outer Join t_sale_h ON t_sale_d.saleno=t_sale_h.saleno   
                              Left Outer Join t_goods on t_sale_d.itemno=t_goods.itemno 
    where  t_goods.vendorno='20441'and t_sale_h.enddate> dateadd(day,-2,getdate())  and depot='0730002'