Using RAISERROR with the SETERROR Option : RAISERROR « Transact SQL « SQL Server / T-SQL Tutorial






6> sp_addmessage
7>   60000,
8>   16,
9>   'Unable to find ID %09d'
10> GO
Msg 15043, Level 16, State 1, Server BCE67B1242DE45A\SQLEXPRESS, Procedure sp_addmessage, Line 137
You must specify 'REPLACE' to overwrite an existing message.
1>
2>
3> RAISERROR (60000, 1, 2)
4> SELECT @@ERROR
5> GO
Unable to find ID (null)

-----------
          0

(1 rows affected)
1> RAISERROR (60000, 1, 2) WITH SETERROR
2> SELECT @@ERROR
3>
4> sp_dropmessage
5>   60000
6> GO
Msg 102, Level 15, State 1, Server BCE67B1242DE45A\SQLEXPRESS, Line 5
Incorrect syntax near '60000'.
1>








20.21.RAISERROR
20.21.1.RAISERROR syntax
20.21.2.Using RAISERROR without an Error Number
20.21.3.RAISERROR (50001, 15, -1, @parm1, @parm2)
20.21.4.Raise exception with parameters
20.21.5.The syntax of the RAISERROR statement: RAISERROR ({message_id|message_string}, severity, state [, argument]...)
20.21.6.Raising a message not defined in sysmessages.
20.21.7.Raise error out of a procedure
20.21.8.Raise error in case of error
20.21.9.Using RAISERROR with the SETERROR Option