Search notes:

SQL: comments

The SQL standard defines two kinds of comments:
A simple comment starts with two hyphens (--) and extends to the next new line or end of statement, whichever is first.
A Bracketed comment starts with a /* and extends to the next */.
In a comment that is introduced by a --, the /* is not recognized as a comment introducer.
Similarly, within /* … */ the -- does not comment out the */.
Apparrently, some SQL dialects allow to nest /* … */ comments (among which there is T-SQL).
The following snippet tries to demonstrate all combinations in a dialect that does not allow nesting comments.. T is SQL text, c is comment:
TTT TTTT TT -- ccc ccc

TTT /* cc ccc
cc cccc
-- */ ccc ccc
ccc */ TTT

/* ccc ccc
ccc 
ccc -- */ TTT

-- /* ccc ccc
TTT TTTT
TTT -- */ ccc
With these rules, its possible to comment out or in a block of code while testing SQL statements with just two hyphens as is is shown below:
-- /*
This text is not a comment.
By just removing the two hyphens
at the beginning, it turns
into a comment.
-- */

Misc

The statement parser considers comments to be equivalent to new lines.
I believe that the standard can be interpreted to mean that bracketed comments can be nested.

See also

In MySQL, comments can also be introduced with a #. Additionally, it seems that -- needs to be followed by a space to be recognized as a comment.
A minimalistic C-Sharp class to remove SQL comments with regular expressions.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1740444204, '18.191.198.56', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL/statement/comment/index(90): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78