Skip to content

SA0229 : This syntax of RAISERROR is discontinued. Rewrite the statement using the current RAISERROR(…) syntax or consider using THROW

The use of deprecated RAISERROR syntax can lead to compatibility issues in newer versions of SQL Server.

The deprecated RAISERROR syntax refers to using RAISERROR integer 'string' , which was deprecated starting in SQL Server 2012 and removed in SQL Server 2014. Developers writing or maintaining T-SQL code must be aware of this to ensure compatibility with current SQL Server versions.

For example:

-- Deprecated RAISERROR syntax
RAISERROR 50001 'An error occurred';

This example shows the usage of the deprecated format, which is not supported starting with SQL Server 2014. Using this syntax can result in errors during execution and maintenance challenges as the database progresses to newer SQL Server versions.

  • This deprecated syntax may cause runtime errors in SQL Server 2014 and later versions.

  • It requires code refactoring to utilize supported syntax, increasing maintenance overhead.

This guidance helps you update T-SQL code by replacing the deprecated RAISERROR syntax with the current RAISERROR or THROW statements to ensure compatibility with newer SQL Server versions.

Follow these steps to address the issue:

1.Identify occurrences of the deprecated syntax in your code, such as RAISERROR 50001 'An error occurred'; .

2.Replace the deprecated syntax with the supported RAISERROR syntax: RAISERROR (message_string, severity, state); Ensure you provide appropriate values for message_string , severity , and state .

3.Alternatively, consider using the THROW statement for simplicity and modernity: THROW 50001, 'An error occurred', 1; Adjust the error number, message, and state as needed for your application.

4.Test the updated code to ensure proper error handling and compatibility with SQL Server 2014 and later versions.

For example:

-- Updated statement using RAISERROR
RAISERROR ('An error occurred', 16, 1);
-- or using THROW
THROW 50001, 'An error occurred', 1;

The rule has a Batch scope and is applied only on the SQL script.

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.

5 minutes per issue.

Deprecated Features, Bugs

Deprecated Database Engine Features in SQL Server 2017

declare @errno int
declare @errmsg varchar(500)
select @errno=@@error
if @errno<>0
begin
select @errmsg='Error: '+ convert(varchar(10),@errno)
raiserror 200016 @errmsg
raiserror(@errmsg,200016,1)
return 1
end
  Message Line Column
1 SA0229 : This syntax of RAISERROR is discontinued. Rewrite the statement using the current RAISERROR(…) syntax or consider using THROW. 9 4

Analysis Rules