有一张表table1
id  flag
 1    0
 2    1如果table1的flag字段改为2时触发修改另外一张表table2的Rec_stat号为2,通过id来关联
id  Rec_stat
 2     1

解决方案 »

  1.   

    create trigger tu_table1 on table1
    for update
    as
    if update(flag) and exists(select 1 from inserted i,deleted d where i.id=d.id and i.flag=2 and isnull(d.flag,0)<>2)
    begin
    update table2
    set Rec_start=i.flag
    from table2,inserted i,deleted d
    where table2.id=i.id and i.id=d.id and i.flag=2 and isnull(d.flag,0)<>2
    end
      

  2.   

    情况复杂了一些
    有一张表table1
    id  flag  form_id
     1    0     df
     2    1     fds如果table1的flag字段改为2时触发修改另外一张表table2的Rec_stat号为2(最新时间的一条记录),通过bill_no与form_id来关联
    id  Rec_stat  bill_no idate
     2     1       df       2007-1-1
      

  3.   

    create trigger tu_table1 on table1
    for update
    as
    if update(flag) and exists(select 1 from inserted i,deleted d where i.id=d.id and i.flag=2 and isnull(d.flag,0)<>2)
    begin
    update table2
    set Rec_start=i.flag
    from table2,inserted i,deleted d
    where table2.bill_no=i.form_id and i.id=d.id and i.flag=2 and isnull(d.flag,0)<>2
    and table2.idate=(select max(a.idate) from table2 a where a.bill_no=table2.bill_no)
    end
      

  4.   

    问题是这样情况又复杂了一些
    有一张表table1
    id  flag  form_id
     1    0     df
     2    1     fds如果table1的flag字段改为2时触发,执行一个存贮过程proc1 传入的参数是form_id
    应该怎么写