开发者

Was this undocumented RAISERROR syntax ever documented and subsequently deprecated?

I'm working on a large SQL Server codebase, some of which has been in development since at least SQL 7 and possibly before.

Throughout the codebase, the method of raising an error is to use the following syntax which is, as far as I can tell, undocumented

RAISERROR <error number> <error message>

The error number can be any value greater than 13000; no corresponding entry needs to exist in the sys.messages table. The error message can also be arbitrary.

The following sample code

raiserror 13000 'test error'

produces the following output

Msg 13000, Level 16, State 1, Line 1
test error

This behaviour is the same in SQL 2000, 2005 and 2008 (I haven't tested 2008 R2).

We're going to attempt to standardise on a supported method, but my question is whe开发者_如何学运维re this behaviour came from in the first place.

I assume this must once have been documented, supported behaviour, but copies of books online for SQL 7 and before are difficult to find. Does anybody know when this was supported or when it was deprecated, if ever?

Edit To clarify, according to the documentation, the supported RAISERROR syntax is

RAISERROR ( { msg_id | msg_str | @local_variable }
    { ,severity ,state }
    [ ,argument [ ,...n ] ] )
    [ WITH option [ ,...n ] ]

And any user error number which is not defined in sys.messages should be raised with an error message id of 50000


This looks like it might be a throwback to SQL Server's origins in Sybase, whose RAISERROR command has this exact syntax:

  • SyBooks Online – Sybase IQ 15.2 > Reference: Statements and Options > SQL Statements – RAISERROR statement [T-SQL]

Whatever its origins, this syntax is deprecated as of SQL Server 2008 R2 and will be removed in SQL Server 2012 (v 11.x). See the Deprecated Database Engine Features in SQL Server 2008 R2 page for details.


A user defined error message is actually from 13000 through to 2147483647.

So the behaviour you are describing is correct - you are raising a user defined error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜