Thomas Andreè Lian February 2016

RAISERROR conversion from SQL Server 8 to 11

I have moved a database form a old legacy MSSQL server 2000 (SQL Server 8) to SQL Server 11 and im receiving some errors in several triggers.

They are formed like this.

RAISERROR 20001 @msg

and

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

so after some reading i see that this is a known change, but i cant find any good known solutions.

At first i thought to just replace them to something like this

RAISERROR ('Field ''comp_v1'' cannot contain a null value.',16,-1)

The issue here is, well i have no real idea on what effect this has, and if there is any good straightforward conversion from the old line to a new line.

Im assuming that there is a reason for the codes 44444 and 20001 etc.

Answers


Rahul Tripathi February 2016

I would advise you to use THROW keyword to throw the error. You can check this for reasons:

With THROW the benefit is: it is not mandatory to pass any parameter to raise an exception. Just using the THROW; statement will get the error details and raise it

whereas with RAISERROR

With RAISERROR developers had to use different ERROR_xxxx() system functions to get the error details to pass through the RAISERROR() statement, like:

  • ERROR_NUMBER()
  • ERROR_MESSAGE()
  • ERROR_SEVERITY()
  • ERROR_STATE()

Post Status

Asked in February 2016
Viewed 1,595 times
Voted 8
Answered 1 times

Search




Leave an answer