Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server return code -6, what does it mean?

I have a stored procedure that works with no issues, that is the return code is 0. In some cases I RAISERROR a user defined error (> 50000). In those cases the return is -6. I am just curious, what does -6 mean? I do not set the return code in the procedure, so this number is SQL Server (system) generated.

I found this statement:

Whether these negative numbers have any meaning, is a bit difficult to tell. It used to be the case, that the return values -1 to -99 were reserved for system-generated return values, and Books Online for earlier versions of SQL Server specified meanings for values -1 to -14. However, Books Online for SQL 2000 is silent on any such reservations, and does not explain what -1 to -14 would mean.

Does anyone know the "hidden" meanings to these return codes?

I am using SQL Server 2008 R2.

like image 569
Jon Raynor Avatar asked Aug 09 '11 18:08

Jon Raynor


1 Answers

OK, I found this...

Return value from a stored proc on error

If you have a RETURN statement with an explicit return value, that is of course the return value.

But if there is no RETURN statement, but an error occurs during execution, the return value is 10 minus the severity level of the error. Division by zero is level 16, thus the return value is -6. Permissions errors are typical level 14, thus the return value is -4.

In my case, the severity of the error I was raising was 16, so 10 - 16 = -6.

Thanks everyone for thier input.

like image 97
Jon Raynor Avatar answered Oct 23 '22 12:10

Jon Raynor