MySQL Reference Sheet: Comments
Comments are very useful, even critical, in any computer based language. They allow developers to leave instructions and explanations for themselves and other developers. They provide a safe space within code to insert notes, dates, authors and any other data that may be useful. Comments are not executed with the rest of the code and will not interfere with the data flow within the code. They can laso be used to comment out code during testing.
There are three options for inserting comments in MySQL, two single-line options and one multi-line option.
Single-line comments
A double dash or hyphen is used to comment out a line of data, thus creating a comment
mysql> SELECT * FROM courses_table;
– – This line is a comment and will not be executed
There is another option or single line comments by using the # symbol:
mysql> SELECT * FROM courses_table;
# This line is a comment and will not be executed
# And this is a separate comment
Using the # symbol works with MySQL but not standard SQL so we advice you not to use it as it will make your code less portable, but know it’s there if you ever see it used within another developers code.
Multi-line comments
A forward slash followed by an asterisk (/*) indicates the start of a multi-line comment in MySQL. This comment will continue, regardless of how many lines the comment occupies, until MySQL sees the combination of an asterisk followed by a forward slash (*/). Thee two character sets indite the start and end of a multi-line comment. A easy way to remember the order of characters is that theĀ asterisk is always closest to the comment content.
Example:
mysql> SELECT * FROM coures_table;
/* This is a comment
that spans
several lines*/
No matter what programming language you are writing you should always include comments in your code.