update(列名)  是否被修改过if update(列名)
begin
......
end 

解决方案 »

  1.   

    那不是每个字段都要设置一个UPDATE???如果有100个字段,那不要设置100个UPDATE?真的没有办法只取得被修改的那个字段?
      

  2.   

    逐个字段比较inserted及deleted中的数据就知道了
      

  3.   

    就是用原子段和inserted 或者deleted 中的数据比较就知道了
      

  4.   

    使用columns_updated()他会返回一个16进制的数字(varbinary类型),你对这个数进行比较就可以了。每个列的值是不一样的。而且,任意几列的和一定不等于某一列的值。如果修改的是多列,返回的是这些列的值的合。
      

  5.   

    首先真诚感谢大家的帮助!!
    问:
    if @@rowcount!=0
       begin 
          insert 另一个表
            values(?)
    怎么逐个比较呢?inserted、 deleted里有新的和旧的数据,但怎么能取到单个字段?又怎么比较,能不能给出具体的程序?谢谢。
    TO 流云:columns_updated()的功能我查看了下帮助功能,但看得不是很懂,像它说的,如果更改了第二、第三、第四列的话,就是:columns_updated()&14,是什么意思,解释是POWER(2,(2-1)+POWER(2,(3-1))+POWER(2,(4-1)=14,能不能解释一下。[email protected]
      

  6.   

    create table t ( 
        Col01 int , Col02 int , Col03 int , Col04 int ,
        Col05 int , Col06 int , Col07 int , Col08 int ,
        Col09 int , Col10 int , Col11 int , Col12 int ,
        Col13 int , Col14 int , Col15 int , Col16 int ,
        Col17 int
    );
    insert into t values (
        1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17
    );create trigger tri_test on t for 
    update
    as
    begin
    declare @i int
    select @i=count(*) from syscolumns where id=object_id('t')
    while @i>0
    begin
    if substring( columns_updated() , (@i-1)/8+1 , 1 ) & power( 2, (@i-1)%8 ) > 0
    print '第'+rtrim(@i)+'列修改'
    set @i=@i-1
    end
    endupdate t set col17=1,col15=1,col16=1,col14=1,col09=1,col11=1,col01=1,col02=1,col03=1结果:
    第17列修改
    第16列修改
    第15列修改
    第14列修改
    第11列修改
    第9列修改
    第3列修改
    第2列修改
    第1列修改drop trigger tri_test
    go
    create trigger tri_test on t for 
    update
    as
    begin
    declare @i int
    select @i=count(*) from syscolumns where id=object_id('t')
    while @i>0
    begin
    if substring( columns_updated() , (@i-1)/8+1 , 1 ) & power( 2, (@i-1)%8 ) > 0
    print col_name(object_id('t'),@i)+'列修改'
    set @i=@i-1
    end
    endgoupdate t set col17=1,col15=1,col16=1,col14=1,col09=1,col11=1,col01=1,col02=1,col03=1Col17列修改
    Col16列修改
    Col15列修改
    Col14列修改
    Col11列修改
    Col09列修改
    Col03列修改
    Col02列修改
    Col01列修改
      

  7.   

    thanks a lot,giving s right now!!!~.~