Migrating from SQL Server 2008r2 to SQL Sever 2012

481 views Asked by At

RAISEERROR not supported in SQL Server 2012

RAISERROR 44444 'Field ''CostCodeId'' cannot contain a null value.'

How to change the syntax to make it to support in sql server 2012. Any alternative please help.

2

There are 2 answers

0
Tak On

In SQL 2012 you should use THROW.

Here is link New THROW statement in SQL Server 2012

0
Manoj Pandey On

For any new development work start using THROW, and if possible start replacing RAISERROR with THROW, as it can be replaced anytime in future (but I don't think in near future).

RAISERROR was deprecated in SQL Server 2012 and replaced by THROW, and it may be completely replaced by THROW in new versions of SQL Server.

With RAISERROR it was mandatory to provide the parameters like error_message, error_number, error+severity, but with THROW all there are optional. THROW gets all this information from the new and improved error handling mechanism and returns the information to the user in case of any exception.