数据库编程的错误处理

BEGIN try
Create table OurIfTest
(
col1 int primary key
)
end try
begin catch
declare @errorNo int,
@severity tinyint,
@state smallint,
@lineNo int,
@message nvarchar(4000)
select 
@errorNo=ERROR_NUMBER(),
@severity=ERROR_SEVERITY(),
@state=ERROR_STATE(),
@lineNo=ERROR_LINE(),
@message=ERROR_MESSAGE()
IF @errorNo=2714
print 'already exits table'
else    
raiserror(@message,16,1)
end catch
原文地址:https://www.cnblogs.com/363546828/p/3056234.html