Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is RAISERROR misspelled? Or is it not?

Tags:

tsql

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.

like image 219
Jason Kleban Avatar asked May 12 '10 17:05

Jason Kleban


People also ask

What is the difference between Raiserror and throw?

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.

What is Raiserror?

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.

How do you use Raiserror?

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.

What is Raiserror state?

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.


2 Answers

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.

like image 200
SqlRyan Avatar answered Oct 10 '22 06:10

SqlRyan


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

  • RAISERROR - Has an MSDN link and it is colored cyan/blue in SSMS
  • RAISEERROR - Doesn't have an MSDN link from what I can find right now and it is colored magenta in SSMS

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; 

This is what happens when I execute this block of code.

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.

like image 36
dyslexicanaboko Avatar answered Oct 10 '22 06:10

dyslexicanaboko