--化解的办法:
declare @s1 varchar(8000),@s2 varchar(8000),@s3 varchar(8000),@s4 varchar(8000)
select @s1='',@s2='',@s3='',@s4=''select @s1=@s1+',@'+gid+' varchar(8000)'
,@s2=@s2+',@'+gid+'='''''
,@s3=@s3+'
select @'+gid+'=@'+gid+'+'',[''+name+'']'' from syscolumns where object_id(''你的表'')=id and name not in(''aa'',''bb'') and ((colid-1)/80)='+gid
,@s4=@s4+'+@'+gid
from(
select distinct gid=cast((colid-1)/80 as varchar)
from syscolumns 
where object_id('你的表')=id and name not in('aa','bb')
) aselect @s1=substring(@s1,2,8000)
,@s2=substring(@s2,2,8000)
-- ,@s4=substring(@s4,16,8000)
exec('declare '+@s1+'
select '+@s2+'
'+@s3+'
select @0=substring(@0,2,8000)
exec(''select '''+@s4+'+'' from 你的表'')')

解决方案 »

  1.   

    想起還有個問題, 就是, 如果一個update 操作引發觸發器, 我又想在觸發器中修改同一記錄,
    也就是說, 
      update tableA set oldField = newField where id = (select id from inserted)
    如何避免引起循環觸發??
      

  2.   

    1: 语句有点问题,不能用=,要用 in
     update tableA set oldField = newField where id in (select id from inserted)2:
    嵌套触发器。
    企业管理器->服务器->属性->服务器设置->允许激发会激发其它触发器(嵌套触发器)的触发器
    勾上即可以嵌套,否则不会嵌套。
      

  3.   

    1. create trigger .......as
      declare @ss varchar(1000)
      select top 1 @ss=id from inserted where number=0
      if @ss is not null
      begin
        raiserror('第'+@ss+'号记录的数量为0,不能处理。',16,1,@ss)
        rollback tran
        return
      end  ........  --没有错误,继续处理。
    除了用户定义错误,其他SQL Server系统运行中的错误,自己会回滚。
      

  4.   

    如果一個update 操作引發觸發器, 我又想在觸發器中修改同一記錄,
    也就是說, 
      update tableA set oldField = newField where id = (select id from inserted)
    如何避免引起循環觸發??
    ----------------------------------------------------------------------
      update tableA set oldField = newField where oldField<>newField and id = (select id from inserted)
      

  5.   

    实际上,触发器中return好像是多余的,rollback本来就会直接结束触发器的运行。不过我习惯了写上一个return。