Comments in MS SQL

igitur's profile image igitur posted 7 years ago in General Permalink

In MS SQL, this is a valid comment:

--select * from table

However, SynEdit doesn't highlight it as a comment. Only if a insert a space after the -- does it recognise it as a comment. In MySQL, the space is required, but not in MS SQL.

igitur's profile image igitur posted 7 years ago Permalink

PS: I first assumed this was a SynEdit bug, so I posted it on their repo. https://github.com/SynEdit/SynEdit/issues/42

ansgar's profile image ansgar posted 7 years ago Permalink

SynEdit does not expect a space for any SQL dialect, and HeidiSQL expects a space for all. There is currently no differentiation for MSSQL, as I was thinking the space is required everywhere.

Rocky's profile image Rocky posted 4 years ago Permalink

What disturbing is: after "--" the line will be gray and italic, it seems to be a comment, but at run it turns out, that there is an error, because it's not a comment. At first I didn't know what the problem is, and finally found, that a space is still missing.

Why is space expected? And if it is expected, it would be good if formatting would change only after adding the space.

ansgar's profile image ansgar posted 4 years ago Permalink

https://dev.mysql.com/doc/refman/5.7/en/comments.html

In MySQL, the -- (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on).

ansgar's profile image ansgar posted 4 years ago Permalink

But the space seems to be MySQL specific. Standard SQL does not require it. Here's the explanation from MySQL: https://dev.mysql.com/doc/refman/5.7/en/ansi-diff-comments.html

Rocky's profile image Rocky posted 4 years ago Permalink

I see, thanks. However it would not be a problem, if in the Query window it would work as comment also without a space. (The only danger is, that somebody writes SQL code in HeidiSQL (with "--" comments) and tries to run it in another environment. What runs here would not run there. So really, it would cause some compatibility issue.)

But if "-- " is required for comment, it would expected that only after it changes the formatting to comment style, not after "--".

BTW: The MySQL Comment Syntax description seems to be erroneous. It says: "(double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, NEWLINE, and so on)" Newline is funny in a single line comment. :)

ansgar's profile image ansgar posted 4 years ago Permalink

The issue in HeidiSQL is its wrong hightlighting. See issue #549, and issue 42 in SynEdit.

Rocky's profile image Rocky posted 4 years ago Permalink

Yes, exactly. Thank you!

Please login to leave a reply, or register at first.