T-SQL的"LineNo"到底是什么?保留字吗? [英] What exactly does the T-SQL "LineNo" reserved word do?
问题描述
我今天在SQL Server 2000上针对表编写查询,在Query Analyzer中编写查询时,令我惊讶的是,我注意到LineNo
一词已转换为蓝色文本.
I was writing a query against a table today on a SQL Server 2000 box, and while writing the query in Query Analyzer, to my surprise I noticed the word LineNo
was converted to blue text.
它似乎是保留字根据MSDN文档,但是我找不到任何信息,只是推测它可能是一个遗留的保留字,什么都没有做.
It appears to be a reserved word according to MSDN documentation, but I can find no information on it, just speculation that it might be a legacy reserved word that doesn't do anything.
我对字段名进行转义没有问题,但是我很好奇–有人知道T-SQL中的"LineNo"实际上是做什么用的吗?
I have no problem escaping the field name, but I'm curious -- does anyone know what "LineNo" in T-SQL is actually used for?
推荐答案
好的,这是完全没有记载的,我不得不通过反复试验来弄清楚,但是它设置了错误报告的行号.例如:
OK, this is completely undocumented, and I had to figure it out via trial and error, but it sets the line number for error reporting. For example:
LINENO 25
SELECT * FROM NON_EXISTENT_TABLE
以上内容会给您一条错误消息,指出第27行有错误(如果您将LINENO行转换为单行注释(例如,在其前面加上两个连字符),则会显示3条错误):
The above will give you an error message, indicating an error at line 27 (instead of 3, if you convert the LINENO line to a single line comment (e.g., by prefixing it with two hyphens) ):
Msg 208, Level 16, State 1, Line 27
Invalid object name 'NON_EXISTENT_TABLE'.
这与编程语言中的类似机制有关,例如Visual C ++和Visual C#中的#line预处理程序指令(顺便说一下).
This is related to similar mechanisms in programming languages, such as the #line preprocessor directives in Visual C++ and Visual C# (which are documented, by the way).
您可能会问,这有什么用?好吧,它的一种用途是帮助SQL代码生成器从某种更高级别的(比SQL)语言生成代码和/或执行宏扩展,将生成的代码行与用户代码行联系起来.
How is this useful, you may ask? Well, one use of this it to help SQL code generators that generate code from some higher level (than SQL) language and/or perform macro expansion, tie generated code lines to user code lines.
P.S.,依靠未记录的功能不是一个好主意,尤其是在处理数据库时.
P.S., It is not a good idea to rely on undocumented features, especially when dealing with a database.
更新:直到并包括SQL Server的当前版本,此说明仍然正确,在撰写本文时,该版本为SQL Server 2008 R2累积更新5(10.50.1753.0).
Update: This explanation is still correct up to and including the current version of SQL Server, which at the time of this writing is SQL Server 2008 R2 Cumulative Update 5 (10.50.1753.0) .
这篇关于T-SQL的"LineNo"到底是什么?保留字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!