Documentation is an important component of coding, and SQL is no exception.
There are two main ways to add comments in SQL:
To add a comment that is only across a single line, we would add two dashes '--'. Everything after these two dashe will be considered as a comment and will not be executed. The line break acts as the end of the comment.
Note that you can add the two dashes in the middle of a line. In that instance, everything before the two dashes will still be considered as part of the code and will be executed, while everything after the two dashes is treated as a comment.
An entire line is used as a comment.
Comments can appear anywhere in the code, even in the middle of a SQL block.
In the code above, the HAVING clause will still execute as only the texts after the two dashes are considered as comments.
To add a comment that spans across multiple lines, we would start the comment block with /* and then end the comment block with */. Everything in between these two markers is considered as a comment. There is no strict rule on what needs to go into the comment block. You can leave open lines, have special characters... it doesn't matter.
In this example, the first three lines are all comments and has no impact on how the code is executed.
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.