如: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未更新
在存储过程中执行了这样的更新,并有效判断此更新是否生效,我当前的方法是: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未更新
--返回受上一语句影响的行数。update tab set a = @a where id = @id --执行更新
if @@rowcount > 0
print '更改成功'
...
=====================
这样的也不严谨,请看下面的语句,别忘了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也在考虑之列!