Is “Version” a Reserved word in TRANSACT-SQL? (Shows Blue but not in Reserved word list)

一个人想着一个人 提交于 2019-12-13 13:09:13

问题


I was writing a Stored Procedure today and Wrote the line:

SELECT pv1.Version FROM depl...

and the word Version turned blue shown below:

so I assumed it was a reserved word, so did some investigating here:

Reserved Keywords (TRANSACT-SQL)

But could not find the word Version in the list.

Is Version a SQL reserved word, and if not why is my word Version displaying blue? I am using SQL Management Studio 2012


回答1:


As you rightly noted, Version is not in the official reserved word list. It's just a "feature" of SQL Server Management Studio that is showing it in blue.

There are many words like this. Here's a few more:

DESCRIPTION
SERVER
INSTEAD

There are even some words that show as pink such as LOOKUP.




回答2:


"Version" is not a SQL Server reserved keyword.

However, it is used in a global variable used to show the OS name & version, SQL Server version, SQL Server patches and hardware attributes of the SQL Server being used.

SELECT @@VERSION

Perhaps the "Version" text turns blue in Transact-SQL because it is known to SQL Server in the context of this global variable. I'm not sure about that, this is just a theory.




回答3:


The short answer - no, it isn't. Here's an SQLFiddle that uses it as a column name in SQL-Server 2014 to prove it.




回答4:


I think you can always if in doubt wrap your column name in brackets to use reserved words as column names:

select p1.[Version] from dpl...



来源:https://stackoverflow.com/questions/30805490/is-version-a-reserved-word-in-transact-sql-shows-blue-but-not-in-reserved-wo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!