表A                   表B
a   b   c              d   e   f  g
x   y   0              1   0   0  0
 
当c更新为1时,把这一行数据插到B中,结果如下
表A                   表B
a   b  c               d   e   f  g
x   y  1               1   0   0  0
                       x   y   0  0IF EXISTS(Select Name From Sysobjects Where Name='aa' And Type='TR')
DROP TRIGGER aa
go
CREATE TRIGGER aa
on
A
after update
as 
if update(c)
declare @a varchar(50),@b as varchar(50)
select @a = a,@b = b from inserted
inser into B (d,e,f,g)~~??这里下去应该怎么写啊??因为d和e能从inserted中找到,但是f和g要赋0~~

解决方案 »

  1.   

    inser into B (d,e,f,g)
    select a,b,0,0 from inserted
      

  2.   

    inser into B (d,e,f,g) select a,b,0,0 from inserted前面4个字段与后面要一一对应
      

  3.   

    declare @a varchar(50),@b as varchar(50) 
    select @a = a,@b = b from inserted 这两句可以不要了,否则同时更新多个的时候会出问题
      

  4.   

    IF EXISTS(Select Name From Sysobjects Where Name='aa' And Type='TR') 
    DROP TRIGGER aa 
    go 
    CREATE TRIGGER aa 
    on 

    after update 
    as 
    if update(c) 
    inser into B (d,e,f,g)
    select a,b,0,0 from inserted
    go
      

  5.   

    直接把筛选条件放在后面inser into B (d,e,f,g)
    select a,b,0,0 from inserted where 条件
      

  6.   


    CREATE TRIGGER aa 
    on 

    after update 
    as 
    if update(c) 
    begin
    inser into B (d,e,f,g)
    select a,b,0,0 from inserted
    end
      

  7.   

    inser into B (d,e,f,g)
    select a,b,0,0 from inserted如果g的值我是从另外一张表C里面找的值呢,C和A,B没有任何关系
      

  8.   

    表A                  表B               表C
    a  b  c              d  e  f  g        FormName   g
    x  y  0              1  0  0  0          A        XY
                                             B        yx当c更新为1时,把这一行数据插到B中,结果如下 
    表A                  表B 
    a  b  c              d  e  f  g 
    x  y  1              1  0  0  0 
                         x  y  0  yx C和A,B没有字段上什么关系,只是根据你插入的那张表,如果你插入A表则g等于xy 如果插入B表则g等于yx这样子
      

  9.   

    IF EXISTS(Select Name From Sysobjects Where Name='aa' And Type='TR') 
    DROP TRIGGER aa 
    go 
    CREATE TRIGGER aa 
    on 

    after update 
    as 
    if update(c) 
    inser into B (d,e,f,g)
    select a,b,0,0 from inserted
    go