Why is RAISERROR misspelled? Or is it not?

后端 未结 5 1008
迷失自我
迷失自我 2020-12-29 19:31

Why isn\'t RAISERROR spelled RAISEERROR? Where is the second E? I could understand if it were some ancient keyword length constraint, but I would

相关标签:
5条回答
  • 2020-12-29 19:41

    why is there still a TIMESTAMP data type? support for old versions. Someone Sybase person long ago decided to make it RAISERROR and not RAISEERROR, when Microsoft made a deal with Sybase they continued the trend.

    0 讨论(0)
  • 2020-12-29 19:47

    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;
    

    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.

    0 讨论(0)
  • 2020-12-29 19:58

    I believe it's intentional in that it is actually easier to read RAISERROR vs RAISEERROR. (see also sp_helprotect for another example), especially when there's no distinction based on case.

    This stuff goes way back into Sybase's history.

    0 讨论(0)
  • 2020-12-29 20:05

    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.

    0 讨论(0)
  • 2020-12-29 20:06

    From Getting feedback / progress from batches and stored procedures by Jens K. Suessmeyer:

    Ever asked yourself why there is only one "e" in Raiserror? That is from the old Sybase days where two [of the same] same character were cut back to only [one]

    0 讨论(0)
提交回复
热议问题