Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
Signals an error and sends a message to the client.
RAISERROR error-number [ format-string ] [, arg-list ]
The error-number is a five-digit integer greater than 17000. The error number is stored in the global variable @@error.
format-string is string up to 255 bytes in length. It can contain placeholders for the arguments in the optional argument list. These placeholders are of the form %nn!, where nn is an integer between 1 and 20.
The RAISERROR statement allows user-defined errors to be signaled and sends a message on the client.
To create new error messages, use the CREATE ERROR statement. To view the messages in the ISYSUSERMESSAGE system table, query the SYSUSERMESSAGE system view.
The extended values supported by the Adaptive Server Enterprise RAISERROR statement are not supported in SQL Anywhere.
If format-string is not supplied or is empty, the error number is used to locate an error message in the system tables. Adaptive Server Enterprise obtains messages 17000-19999 from the SYSMESSAGES table. In SQL Anywhere this table is an empty view, so errors in this range should provide a format string. Messages for error numbers of 20000 or greater are obtained from the ISYSUSERMESSAGE system table.
Intermediate RAISERROR status and code information is lost after the procedure terminates. If at return time an error occurs along with the RAISERROR then the error information is returned and the RAISERROR information is lost. The application can query intermediate RAISERROR statuses by examining @@error global variable at different execution points.
Not in the standard.
The RAISERROR statement cannot be used in Transact-SQL compound statements and procedures.
This example uses RAISERROR to disallow connections.
CREATE PROCEDURE DBA.login_check() BEGIN // Allow a maximum of 3 concurrent connections IF( DB_PROPERTY('ConnCount') > 3 ) THEN RAISERROR 28000 'User %1! is not allowed to connect -- there are ' || 'already %2! users logged on', Current User, CAST( DB_PROPERTY( 'ConnCount' ) AS INT )-1; ELSE CALL sp_login_environment; END IF; END go GRANT EXECUTE ON DBA.login_check TO PUBLIC go SET OPTION PUBLIC.login_procedure='DBA.login_check' go