我很菜,别要笑我
问题如下
有一table:a如下
a    b   is_confirmed   uid
11   22        N         1
33   44        N         2
table: b
a1   b1   uid现在我要的是当a表的 is_confirmed update为Y的时候我要将update为Y的那笔资料insert到 b表 ,a对应a1,b对应b1,uid为自动递增,不用管!
Create TRIGGER xxx for update 
as
begin
???end谢谢

解决方案 »

  1.   

    说明一下,b表和a表没有任何对应关系,
    b表的a1,b1是可以被修改的
      

  2.   

    Create TRIGGER xxx on a 
    for update 
    as
    begin
    if update(is_confirmed) and exists(select 1 from inserted i,deleted d where i.a=d.a and i.b=d.b and i.is_confirmed='Y' and d.is_confirmed='N')
    insert into b(a1,b1)
    select a,b from inserted i,deleted d
    where i.a=d.a and i.b=d.b and i.is_confirmed='Y' and d.is_confirmed='N'
    end
      

  3.   

    看样子,B表好像事 拿来作A表 的 操作记录的 ,应该不用考虑重复
    Create TRIGGER tr_up on [Table a]
    for update 
    as
    IF UPDATE (is_confirmed)
    begin
    insert into [Table b](a1,b1) select a,b from [Table a] where is_confirmed='Y'    
    end
      

  4.   

    不重复的话就好说了, 不用去搜索[Table a]直接从inserted取 
    Create TRIGGER xxx on a for update as
    begin
    insert into b(a1,b1) select a,b from inserted i,deleted d
    where i.a=d.a and i.b=d.b and i.is_confirmed='Y' and d.is_confirmed='N'
    end
      

  5.   

    楼上的代码只要更新is_confirmed字段就会将a表所有is_confirmed='Y'的记录向b表插入一次.
      

  6.   

    ALTER TRIGGER tr_up on a
    for update 
    as
    IF UPDATE (is_confirmed)
    begin
    IF NOT EXISTS (select * from a,b where b.a1=a.a and b.a2=a.b )
    insert into [b](a1,A2) select a,b from [a] where is_confirmed='Y'    
    end
      

  7.   

    加上一句就OK  如上的 修改,gahade(与君共勉) 的方法事严谨的,就是代码太多了,不过我记得在哪本书上看过 代码多的执行速度还要快些,具体是不是就不太清除了。
    大家的方法都很 不错撒