SQL Server 2005 error handling
来源:互联网 发布:重庆时时彩做号软件 编辑:程序博客网 时间:2024/04/26 15:41
Extract from : SQL Server Error Handling Workbench
http://www.simple-talk.com/sql/t-sql-programming/sql-server-error-handling-workbench/
--Catch Error:
--=============================================
BEGIN TRY
BEGIN TRAN
UPDATE Test SET Col1 = 1/0
COMMIT TRAN
END TRY
BEGIN CATCH
IF (XACT_STATE()) = -1
BEGIN
ROLLBACK TRAN;
RETURN ERROR_NUMBER();
END
ELSE IF (XACT_STATE()) = 1
BEGIN
--it now depends on the type of error or possibly the line number
--of the error
IF ERROR_NUMBER() = 8134
BEGIN
ROLLBACK TRAN;
RETURN ERROR_NUMBER();
END
ELSE
BEGIN
COMMIT TRAN;
RETURN ERROR_NUMBER();
END
END
END CATCH
-- Retry if error occurs:
--=============================================
DECLARE @retry AS tinyint,
@retrymax AS tinyint,
@retrycount AS tinyint;
SET @retrycount = 0;
SET @retrymax = 2;
SET @retry = 1;
WHILE @retry = 1 AND @retrycount <= @retrymax
BEGIN
SET @retry = 0;
BEGIN TRY
UPDATE HumanResources.Employee
SET ContactID = ContactID
WHERE EmployeeID = 100;
END TRY
BEGIN CATCH
IF (ERROR_NUMBER() = 1205)
BEGIN
SET @retrycount = @retrycount + 1;
SET @retry = 1;
END
END CATCH
END
- SQL Server 2005 error handling
- Handling SQL Server Errors in Nested Procedures
- 谈谈基于SQL Server 的Exception Handling
- 谈谈基于SQL Server 的Exception Handling
- Error Handling
- Error Handling
- 安装SQL Server 2005 error
- Handling workloads on SQL Server 2008 with Resource Governor
- [原创-总结]谈谈基于SQL Server 的Exception Handling
- [原创]谈谈基于SQL Server 的Exception Handling - PART III
- [原创]谈谈基于SQL Server 的Exception Handling - PART II
- [原创]谈谈基于SQL Server 的Exception Handling - PART I
- SQL Server 2005安装失败,ERROR:29534
- SQL Server 2005升级失败: ERROR: 1642
- SQL Server 2005 安装失败 ERROR:1053
- SQL Server 2005 Service Broker Error 15517
- sql server 2005 T-SQL @@ERROR (Transact-SQL)
- SQL Server error 5120
- 访企业工作流管理专家胡长城有感
- 矿泉水网络又一天:思考网络媒体的自由度
- 2007年值得去思考的N大软件技术(1)
- 视频专访:国内著名IE外壳浏览器Maxthon公司CEO Jeff Chen
- 对话国内著名IE外壳浏览器Gosurf主创人-徐骞
- SQL Server 2005 error handling
- 对话Firefox Gecko内核开发者:李沫南
- 扎根IE开发拥有自己理想的程序员--张硕
- PC时代IE浏览器获胜,Web时代呢?
- TIOBE 2006年8月最流行开发语言排名 Ruby上窜迅猛
- 我为什么不喜欢Qihoo?
- 我们为什么要推出ASP.NET栏目?
- Vista MMC和PowerShell未达目标并更名"Aspen"
- "微软收购Zend"假新闻看开源需要新心态