Sql2005中可以使用Try Catch 语句来捕获异常了,不过这个只能捕获一般的异常像连接错误的异常是不能捕获的 具体用法如下:
Sql2005中可以使用Try Catch 语句来捕获异常了,不过这个只能捕获一般的异常像连接错误的异常是不能捕获的 具体用法如下:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
-- =============================================
-- Author: <Hongyu Niu>
-- Create date: <2007-7-21>
-- Description: 插入一条重大危险源档案信息
-- Return Value:
-- =============================================
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
ALTER PROCEDURE [dbo].[P_DangerSource_File_Add]
@SourceName varchar(50), --名称
@TypeID int, --类型
@DangerLevel varchar(30), --危险级别
@IsControl bit, --是否监控
@SourceLocation varchar(200), --危险源地点
@SourceNum int, --危险源数量
@Descrip varchar(200), --对危险源描述
@Accident varchar(150), --可能发生事故
@Summarize varchar(200), --概述
@Supervisor varchar(30), --负责人
@Telephone varchar(50), --联系电话
@UserID varchar(50), --登记人ID
@InDate datetime, --登记日期
@IsChanged bit, --是否变更
@DeptID varchar(20) --部门ID
AS
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
Begin Try
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
INSERT INTO T_DangerSource_File (
[SourceName],
[TypeID],
[DangerLevel],
[IsControl],
[SourceLocation],
[SourceNum],
[Descrip],
[Accident],
[Summarize],
[Supervisor],
[Telephone],
[UserID],
[InDate],
[IsChanged],
[DeptID]
) VALUES (
@SourceName,
@TypeID,
@DangerLevel,
@IsControl,
@SourceLocation,
@SourceNum,
@Descrip,
@Accident,
@Summarize,
@Supervisor,
@Telephone,
@UserID,
@InDate,
@IsChanged,
@DeptID
)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
return SCOPE_IDENTITY()
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
End Try
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
Begin Catch
return -1
End Catch
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)