SQL Formatting issues
As I almost exclusively stick to SQL Server related tags, I've picked up on a few issues/features with the sql language formatting.
Hash character incorrectly interpreted as comment character in SQL
In the below example, on the first line, everything after the #
in VIN#
is a coloured as a comment. On the third line, everyting after the #
in #TempTable
is. This doesn't, however, occur within the literal string, does within brackets ([]
) (used by T-SQL as a delimit identifier), and doesn't within double quotes ("
) (the ANSI SQL delimit identifier).
SELECT VIN#, NTT.fID, GETDATE(), SYSDATETIME()FROM #TempTable TT JOIN dbo.NonTempTable NTT ON TT.ID = NTT.fIDWHERE Description = 'Hello#there' AND NTT.Val = 3 AND [VIN#] > 7 OR "VIN#" < -12;--This is an actual single line comment/* This is aMultilineComment*/
#
isn't even a comment character in SQL. Single line comments are defined with --
and multiple with /* ... */
.
This is actually quite a problem, especially when temporary objects start with a #
, and are used frequently with DDL and DML examples.
Further edit
Brackets ([]
) not treated as delimit identifier
In T-SQL (as stated above) Brackets ([]
) are the default delimit identifier, rather that double quotes ("
), which are the ANSI delimit Identifier.
If a key work is within brackets, it is highlighted incorrectly. For example:
SELECT [name]FROM dbo.[Table] T JOIN dbo."VIEW" V ON T.ID = V.IDl
I did decide to check, and there isn't a T-SQL variant option:
SELECT [name]FROM dbo.[Table] T JOIN dbo."VIEW" V ON T.ID = V.IDl
Another edit:
The @ character isn't recognised as a variable identifier
Variable names aren't highlighted, or "immune" to other highlighting. Variable names are prefixed with an @
in SQL. For example:
DECLARE @variable varchar(10), @Table table (ID int), @Date datetime2(0), @1 int, @NonReservedWord sysname;
Notice that all the variable names, apart from NonReservedWord
, receive incorrect syntax highlighting.