ON_TSQL_ERROR Option [TSQL]

Controls error handling in stored procedures.

Allowed Values

Value Description
STOP Stops execution immediately upon finding an error.
CONDITIONAL If the procedure uses ON EXCEPTION RESUME, and the statement following the error handles the error, continue; otherwise, exit.
CONTINUE Continue execution, regardless of the following statement. If there are multiple errors, the first error encountered in the stored procedure is returned. This option most closely mirrors Adaptive Server behavior.

Default

CONDITIONAL

Scope

Option can be set at the database (PUBLIC) or user level. When set at the database level, the value becomes the default for any new user, but has no impact on existing users. When set at the user level, overrides the PUBLIC value for that user only. No system privilege is required to set option for self. System privilege is required to set at database level or at user level for any user other than self.

Requires the SET ANY PUBLIC OPTION system privilege to set this option. Can be set temporary for an individual connection or for the PUBLIC role. Takes effect immediately.

Remarks

ON_TSQL_ERROR controls error handling in stored procedures.

Both CONDITIONAL and CONTINUE settings for ON_TSQL_ERROR are used for Adaptive Server compatibility, with CONTINUE most closely simulating Adaptive Server behavior. The CONDITIONAL setting is recommended, particularly when developing new Transact-SQL stored procedures, as CONDITIONAL allows errors to be reported earlier.

Adaptive Server compatibility is described in Reference: Building Blocks, Tables, and Procedures.

When this option is set to STOP or CONTINUE, it supersedes the setting of the CONTINUE_AFTER_RAISERROR option. However, when this option is set to CONDITIONAL (the default), behavior following a RAISERROR statement is determined by the setting of the CONTINUE_AFTER_RAISERROR option.

Related reference
CREATE PROCEDURE Statement
CREATE PROCEDURE Statement [T-SQL]
RAISERROR Statement [T-SQL]
CONTINUE_AFTER_RAISERROR Option [TSQL]