Why does the column name "source" get rendered in grey in SSMS & VS T-SQL editor?
Asked Answered
C

1

12

I have the following simple tSQL to create a table

CREATE TABLE NewsArticles
(id INT NOT NULL IDENTITY(1, 1) PRIMARY KEY,
lastCrawl DATETIME NULL,
snippet NVARCHAR(2083) NULL,
source NVARCHAR(2083) NULL,
title NVARCHAR(2083) NULL,
url NVARCHAR(2083) NULL)

In both Visual Studio 2012 and SQL Server 2012 Management Studio "source" is rendered in grey while the other column names are rendered green in SSMS or black in VS. Why? The word "source" does not appear to be a reserved word in the list of SQL reserved keywords

enter image description here

Contortive answered 13/7, 2012 at 10:8 Comment(3)
This may seem an abstract unimportant question, but I'm getting errors when I try to insert rows from LINQ that have the source column set to null and during diagnosis I was struck by the different rendering.Contortive
It is a keyword used in MERGE. i.e. WHEN NOT MATCHED BY SOURCEArduous
Perfect - I think that's an answer, thanks Martin. Do you want to move it from comment to answer and I'll mark it as such?Contortive
A
13

It is a keyword used in MERGE. i.e. WHEN NOT MATCHED BY SOURCE.

The word MATCHED also exhibits the same behaviour in that it gets highlighted grey in the editor.

Neither of these are reserved keywords though so if used as an identifier they do not need to be delimited (unless you find the syntax highlighting distracting).

Arduous answered 13/7, 2012 at 10:28 Comment(2)
Follow up question; if you are using 'source' or 'matched' in a query, should you escape it somehow or enclose it in brackets?Stonge
@n00b, you do not need to escape "source". I have not tested "matched", however.Scrutator

© 2022 - 2024 — McMap. All rights reserved.