update 时会产生两个临时表
deleted 和inserted
delete 是产生一个:deleted
insert into 是产生一个临时表 insered

解决方案 »

  1.   

    IF UPDATE(Organization_Chi)
    Update D_Forum_Representative  Set 
    Organization_Chi = a.Organization_Chi
    from inserted a
    Where Main_Representative_ID=a.Representative_ID and a.other_identity<>'1'
     delete from D_Forum_Representative 
     where Main_Representative_ID in(select Representative_ID from deleted where other_identity = '1') 
      

  2.   

    create TRIGGER [TRIG_D_Forum_Representative_other] ON dbo.D_Forum_Representative 
    FOR UPDATE
    AS
    Begin
    IF UPDATE(Organization_Chi)
      Update D_Forum_Representative Set Organization_Chi=a.Organization_Chi from inserted a Where D_Forum_Representative.Main_Representative_ID=a.Representative_ID and other_identity<>'1'
      

  3.   

    create TRIGGER [TRIG_D_Forum_Representative_other] ON dbo.D_Forum_Representative 
    FOR INSERT
    AS
    Update D_Forum_Representative Set Organization_Chi=a.Organization_Chi from inserted a Where D_Forum_Representative.Main_Representative_ID=a.Representative_ID and other_identity<>'1'
      

  4.   

    CREATE TRIGGER [TRIG_D_Forum_Representative_other] ON dbo.D_Forum_Representative 
    FOR delete
    as
    update D_Forum_Representative set Main_Representative_ID=null from deleted a where a.Representative_ID=D_Forum_Representative.Main_Representative_ID
      

  5.   

    create TRIGGER [TRIG_D_Forum_Representative_other] ON dbo.D_Forum_Representative 
    FOR UPDATE
    AS
    Begin
    IF UPDATE(Organization_Chi)
      Update D_Forum_Representative Set Organization_Chi=a.Organization_Chi-b.Organization_Chi from inserted a
    deleted b Where a.Main_Representative_ID=b.Representative_ID  and D_Forum_Representative.Main_Representative_ID=a.Representative_ID and other_identity<>'1'
      

  6.   

    关于删除的触发器如何实现
    现在是这样几种情况
    when (deleted.other_identity = ‘1‘)
    then 
       delete from D_Forum_Representative 
          where D_Forum_Representative.main_Representative_id=
                deleted.representative_id
    else when (deleted.other_identity <>‘1‘)
       update from D_Forum_representative
       set D_Forum_representative.ww = D_Forum_representative.ww - 1
      

  7.   

    if exists(select * from deleted where other_identity = ‘1')
        delete from D_Forum_Representative 
          where D_Forum_Representative.main_Representative_id=
                deleted.representative_id
    else
       update from D_Forum_representative
       set D_Forum_representative.ww = a.ww - 1
    from deleted a
    D_Forum_Representative.main_Representative_id=
                a.representative_id
      

  8.   

    或者    delete from D_Forum_Representative 
          where D_Forum_Representative.main_Representative_id=
                deleted.representative_id and deleted.other_identity = ‘1'
     update from D_Forum_representative
       set D_Forum_representative.ww = a.ww - 1
    from deleted a
    D_Forum_Representative.main_Representative_id=
                a.representative_id and .other_identity <>‘1'
      

  9.   

    以上有错,在from deleted a加 where 
    update from D_Forum_representative
       set D_Forum_representative.ww = a.ww - 1
    from deleted a where
    D_Forum_Representative.main_Representative_id=
                a.representative_id and .other_identity <>‘1'
      

  10.   

    CREATE TRIGGER [TRIG_D_Forum_Representative_other] ON dbo.D_Forum_Representative 
    FOR delete
    asdelete D_Forum_Representative  where main_Representative_id in (select representative_id from deleted where ther_identity <>'1')
    update D_Forum_representative  set D_Forum_representative.ww=D_Forum_representative.ww - 1 from deleted a where a.representative_id=D_Forum_representative.representative_id and a.other_identity<>'1'
      

  11.   

    deleted 中的记录就是delete的记录
    将deleted当一个表即可
    在UPDATE时DELETED是修改前的记录,INSERTED是修改后的记录应该清楚了