Why isn't RAISERROR
spelled RAISEERROR
? Where is the second E? I could understand if it were some ancient keyword length constraint, but I wouldn't expect it to be a nine-character limit.
Is RAIS or RROR a technical word such that "raise-error" is just a mis-reading? Are its (immediate) origins in a different language?
I've searched Google but not finding much on the subject.
According to the Differences Between RAISERROR and THROW in Sql Server: Both RAISERROR and THROW statements are used to raise an error in Sql Server. The journey of RAISERROR started from Sql Server 7.0; whereas the journey of the THROW statement has just began with Sql Server 2012.
RAISERROR is a SQL Server error handling statement that generates an error message and initiates error processing. RAISERROR can either reference a user-defined message that is stored in the sys. messages catalog view or it can build a message dynamically.
RAISERROR can either reference a user-defined message stored in the sys. messages catalog view, or build a message dynamically. The message is returned as a server error message to the calling application or to an associated CATCH block of a TRY... CATCH construct.
This is the documentation on state: "state Is an integer from 0 through 255. Negative values default to 1. Values larger than 255 should not be used.
Interesting - I've honestly never even noticed that before.
I would suspect that it's an early oversight that was just never corrected, though I'm a little surprised that support wasn't later added for RAISEERROR, with the mis-spelling left alone for compatibility.
Update: Aparently, there's even some internal confusion about what it ought to be - Check out this connect request, though MSFT didn't respond to it.
I had the same question which is why I stumbled across this post. From what I can see there actually is a difference and the spelling isn't the only thing different between the two cases. These two functions are not equivalent because of the usage.
Links and colors
Credit where credit is due - the color observation was raised already by user Sahuagin in the comments under the question above.
Are you using SQL Server 2012?
Before I move on I think it is fair to state that if you are using SQL Server 2012 or higher, DO NOT USE RAISERRROR! You should be using THROW.
So what's the difference?
You can use RAISERROR (blue) in a single inline statement, versus using RAISEERROR (magenta) which depends on being contained inside of different code block it seems like; based on the error that is returned. The exact syntax error is the following:
Incorrect syntax near 'RAISEERROR'. Expecting CONVERSATION, DIALOG, DISTRIBUTED or TRANSACTION.
RAISERROR Example (One E - blue)
DECLARE @foo varchar(200) SET @foo = '' IF NULLIF(@foo, '') IS NULL BEGIN -- To fix this line, remove one "E" to read RAISERROR RAISEERROR('Not enough Vespene Gas!', 16, 1); RETURN -- This is required otherwise execution will continue! END -- You need the RETURN above or this will execute SELECT Critical_TSqlLine = 1;
Now if you just remove one "E" from the above code, that will function just fine. I didn't provide the execution results, but if you open up SSMS and drop that in and execute I guarantee it will work.
RAISEERROR Example (Two Es - magenta)
I spent entirely too much time trying to figure out how to use this version of the function and I cannot provide an example where this will actually work. I looked into using CONVERSATION, DIALOG, DISTRIBUTED or TRANSACTION and I couldn't get the syntax to work. Long story short, don't concern yourself with this version just use the single E version. For those of you using SQL Server 2012, this shouldn't concern you anymore anyhow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With