Sunday 25 May 2014

How to handle erros in T-SQL code ?

From SQL Server 2005 introduced a TRY ... CATCH statements that you can use to provide error handling.
  • A TRAY block must be followed immediately by a single CATCH block
  • When an error occurs in a statement within a TRY block, control is passed to the CATCH block where the error can be processed. If no error occurs inside the TRY block, the CATCH  block is skipped.
  • Within a CATCH  block, you can use the functions shown in this figure to return data about the error that caused the CATCH block to be executed.
Syntax:
BEGIN TRY
{sql_statement / statement block}
END TRY
BEGIN CATCH
{sql_statement / statement block}
END CATCH

No comments:

Post a Comment