这个是得到的结果
表table1 ,                        表table2
id     anum           id   bnum  --bnum  bit字段
1       11             1     1
2       222            2     1
3       33             3     0
因为我只接收到id=2的参数。从而触发了table2的更新。

解决方案 »

  1.   

    create table taba (id int,aname varchar (10),amun varchar (10))create table tabb (id int,bname varchar (10),bmun varchar (10))
     insert into taba 
    select 1,'aa1','11' union
    select 2,'aa2','22'
     insert into tabb
    select 1,'bb1','1' union
    select 2,'bb2','0'    
    CREATE TRIGGER [TRI_up] ON [taba] 
    FOR UPDATE
    AS
    if update (amun)update 表b set bmun='1'
    from tabb b inserted c where b.id=c.id
      

  2.   

    这样就可以了
    从inserted里提出修改的ID
      

  3.   

    create trigger tr_table1_update
    on table1
    for update
    asupdate table2
    set bnum=1
    from inserted i
    where i,id-table2,idgo
      

  4.   

    create table taba (id int,aname varchar (10),amun varchar (10))create table tabb (id int,bname varchar (10),bmun varchar (10))
     insert into taba 
    select 1,'aa1','11' union
    select 2,'aa2','22'
     insert into tabb
    select 1,'bb1','222' union
    select 2,'bb2','333'    
    CREATE TRIGGER [TRI_up] ON [taba] 
    FOR UPDATE
    AS
    if update (amun)update tabb set bmun='1'
    from tabb b,inserted c where b.id=c.idUPDATE TABA SET amun='99' where id=1
      

  5.   

    create trigger tr_table1_update
    on table1
    for update
    asupdate table2
    set bnum=1
    from inserted i
    where i.id=table2.idgo
      

  6.   


    ---建表
    create table taba (id int,aname varchar (10),amun varchar (10))create table tabb (id int,bname varchar (10),bmun bit)---插入数据
     insert into taba 
    select 1,'aa1','11' union
    select 2,'aa2','22' union
    select 3,'aa3','33'
     insert into tabb
    select 1,'bb1',1 union
    select 2,'bb2',0 union
    select 3,'bb3',0
    ---对taba表建立触发器CREATE TRIGGER [TRI_up] ON [taba] 
    FOR UPDATE
    AS
    if update (amun)update tabb set bmun='1'
    from tabb b,inserted c where b.id=c.id
    ----测试UPDATE TABA SET amun='222' where id=2
    ---结果select * from tabb
    ----------
    id   bname   bmun
    --   -----   ----
    1    bb1 1
    2    bb2 1
    3    bb3 0