我有两个数据表a,b
a表有列名x,y,w,q,d,t,u,o
b表同样列名
主要想实现,如果a表的一条或几条被改动,就在b表中更新同样的列名的数据。请帮忙写一下谢谢

解决方案 »

  1.   

    create trigger  tri_test on a  for update as 
    if update (med_amount) or update (med_sprice) or update (med_jine) begin 
    SET NOCOUNT ON
    update b set med_jine=med_sprice*med_amount  where   a.*=b.*
    end
      

  2.   

    “update b set med_jine=med_sprice*med_amount  where   a.*=b.*”这是什么意思
    能不能按照
    "我有两个数据表a,b
    a表有列名x,y,w,q,d,t,u,o
    b表同样列名
    主要想实现,如果a表的一条或几条被改动,就在b表中更新同样的列名的数据。请帮忙写一下谢谢"这个写
      

  3.   

    create trigger  tri_test on a  for update as 
    if update (x) or update (y) or update (w) or update (q) or update (d) or update (t) or update (u)or update (o)    begin 
    SET NOCOUNT ON
    update b set x=a.x,y=a.y,w=a.w,q=a.q,t=a.t,u=a.u,o=a.o, from a,b
    where   a.*=b.*
    end
      

  4.   

    楼主,A表和B表的关联列要保证不被修改
    假设x,y,w,q,d,t,u,o都是关联列名
    create trigger  tri_test on a  for update as 
    if exists(select * from b inner join inserted a on
     x=a.x and y=a.y and w=a.w and q=a.q and d=a.d and t=a.t and u=a.u and o=a.o)
    begin
    update b set 列名=a.列名,............--等等
    from inserted a where 
    x=a.x and y=a.y and w=a.w and q=a.q and d=a.d and t=a.t and u=a.u and o=a.o
    end