November 18th, 2010
admin
RAISERROR statement is used to return error messages to the business applications that executes SQL statements. The usual errors returned by the SQL server may not make much sense to the business applications users hence we overwrite it by using RAISERROR to display meaningful messages. The statement uses same format as a system error or warning messages generated by SQL server.
You can return a user-defined error message by using RAISERROR. The general syntax is as below
RAISERROR ( { msg_id | msg_str | @local_variable }
{ ,severity ,state }
[ ,argument [ ,...n ] ] )
[ WITH option [ ,...n ] ]
ExamplesRAISERROR (‘Error raised in TRY block.’, — Message text.
Read more…
Categories: Error Messages, Errors, Functions and DMVs, Operators, SQL Queries, SQL Server, T-SQL, T-SQL Tags: errors, functions, raiserror, sql queries, SQL Server, T-SQL, try catch
November 16th, 2010
admin
A TRY ….CATCH construct includes a TRY block followed by a CATCH block. The TRY block contains a set of transact SQL statements. If an error occurs in any statements of the TRY block, the control is passed to the CATCH block, which contains another set of SQL statements.
The CATCH block contains SQL statements that executes only during errors in TRY block. The general syntax of the TRY…CATCH block is as shown below
BEGIN TRY
<SQL Statements…..>
<SQL Statements…..>
END TRY
BEGIN CATCH
<SQL Statements…..>
<SQL Statements…..>
END CATCH
Read more…
Categories: Error Messages, Functions, Functions and DMVs, Insert, SQL Queries, SQL Server, T-SQL, T-SQL Tags: error message, error number, error severity, errors, SQL Server, T-SQL, Transact SQL, try catch