Sets @@ERROR to 0 by default for severity one through ten messages. The WITH SETERROR option sets the @@ERROR value to the msg_id argument or 50000 regardless of the severity.
For additional syntax information for the RAISERROR statement, see the Microsoft SQL Server Transact-SQL Reference.
RAISERROR ({msg_id | msg_str}, severity, state
[, argument1 [, argument2]])
[WITH options]
where
options | Description |
---|---|
LOG | Logs the error in the server error log and the event log. This option is required for messages with a severity level of 19 through 25, and it can be issued only by the system administrator. |
NOWAIT | Sends messages immediately to the client server. |
SETERROR | Sets @@ERROR value to msg_id or 50000 regardless of the severity level. |
This statement now sets @@ERROR to 0 if the severity is between 1 and 10 inclusive. Messages with severity levels 10 and under are not errors, but they do provide additional information.
If you set the msg_id by using the SETERROR option, the RAISERROR statement assigns the msg_id to the @@ERROR regardless of severity.
Otherwise, other behaviors of the RAISERROR statement remain the same.
Important In SQL Server version 6.0, for messages with severity levels 10 and under, @@ERROR is set to 50000. To revert to SQL Server version 6.0 behavior, use either the SETERROR option or trace flag 2701.
For more information about trace flag 2701, see Trace Flags .
This example returns an @@ERROR value of 50000.
RAISERROR('Test Only',1,2) WITH SETERROR
This example returns an @@ERROR value of 101.
RAISERROR (101, 1, 2) WITH SETERROR