AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL Comment |
|
SQL > SQL Commands >
Comment
Documentation is an important component of coding, and SQL is no exception. SQL supports two comment styles: single-line comments using
-- and multi-line comment blocks using /* ... */. Neither style affects query execution — they exist purely to document and explain your code.There are two main ways to add comments in SQL: Method 1: Single lineTo 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. Example 1:An entire line is used as a comment. Example 2: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. Method 2: Multiple linesTo 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. Example:In this example, the first three lines are all comments and has no impact on how the code is executed. Frequently Asked QuestionsQ: How do you write a single-line comment in SQL? Q: How do you write a multi-line comment in SQL? Q: Can a SQL comment appear in the middle of a query? Q: Are SQL comments supported in all databases? |
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.