begin try update ele_cardnum set cardnum = @cardnum where cardid=@cardid, --如果确实修改了数据 if @@rowcount > 0 begin .... end end try begin catch --更新语句报错了 end catch
更看以下的SQL SERVER文档:
@@ROWCOUNT 返回受上一语句影响的行数。语法 @@ROWCOUNT返回类型 integer注释 任何不返回行的语句将这一变量设置为 0 ,如 IF 语句。示例 下面的示例执行 UPDATE 语句并用 @@ROWCOUNT 来检测是否有发生更改的行。UPDATE authors SET au_lname = 'Jones' WHERE au_id = '999-888-7777' IF @@ROWCOUNT = 0 print 'Warning: No rows were updated' 请参见@@ERROR系统函数
begin try
update ele_cardnum set cardnum = @cardnum where cardid=@cardid,
--如果确实修改了数据
if @@rowcount > 0
begin
....
end
end try
begin catch
--更新语句报错了
end catch
@@ROWCOUNT
返回受上一语句影响的行数。语法
@@ROWCOUNT返回类型
integer注释
任何不返回行的语句将这一变量设置为 0 ,如 IF 语句。示例
下面的示例执行 UPDATE 语句并用 @@ROWCOUNT 来检测是否有发生更改的行。UPDATE authors SET au_lname = 'Jones'
WHERE au_id = '999-888-7777'
IF @@ROWCOUNT = 0
print 'Warning: No rows were updated'
请参见@@ERROR系统函数