如何在SQL存储过程中处理错误

如题所述

--1、查询容错处理
select * from è¡¨å
if @@Rowcount=0
begin
    print '无记录'
end

--2、插入容错处理
insert into è¡¨å (col1,col2...) values (val1,val2...)
if @@Rowcount=0 or @@error<>0
begin
    print '插入时发生错误'
end

--3、更新容错处理
update è¡¨å set col1=val1,col2=val2 where æ¡ä»¶
if @@Rowcount<>1 or @@error<>0
begin
    print '更新时发生错误'
end

--4、删除容错处理
delete è¡¨å where æ¡ä»¶
if @@Rowcount<1 or @@error<>0
begin
    print '删除时发生错误'
end
温馨提示:答案为网友推荐,仅供参考