如:update tab set a = 1 where id = 122
在存储过程中执行了这样的更新,并有效判断此更新是否生效,我当前的方法是:create proc sp_test @a int, @id int as
declare @aa int
select @aa = a from tab where id = @id --先取出未更新前的a值
update tab set a = @a where id = @id   --执行更新
if @@error=0 and @aa!=@a
--字段a更新成功
else
--a未更新

解决方案 »

  1.   

    if @@error=0 and @@rowcount!=0
      

  2.   

    @@rowcount
    --返回受上一语句影响的行数。update tab set a = @a where id = @id   --执行更新
    if @@rowcount > 0
    print '更改成功'
      

  3.   

    if @@error=0 and @aa<>@a and @@rowcount<>0 --防止更新数据相同
    ...
      

  4.   

    if @@error=0 and @@rowcount!=0就可以了吧!
      

  5.   

    if @@error=0 and @aa<>@a and @@rowcount<>0 
    =====================
    这样的也不严谨,请看下面的语句,别忘了B如果原始为NULL:Create Table #Temp(A int,B int)
    Insert Into #Temp Values(1,Null)Declare @a int
    Set @a = 1declare @aa int
    select @aa = B from #Temp where A = 1 --先取出未更新前的a值update #Temp set B = @a  where A = 1   --执行更新if @@error=0 and @aa<>@a and @@rowcount<>0 
     print 'S'
    else
     print 'F'Drop Table #Temp
    ==================可行的方法之一是在给@aa赋值时,加上IsNULL()处理。
    而且,如果@a为NULL也在考虑之列!
      

  6.   

    废话很多,呵呵。只要@@RowCount > 0 And @@Error = 0 就行了。这种牛角 问题就不要钻了,有时间多研究下SQL的原理吧。