Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (4k points)
closed by

I want to add comment in SQL code. How can I do this? I'm using MySQL.

closed

4 Answers

0 votes
by (11.4k points)
 
Best answer

To add comments in SQL code when using MySQL, you can follow these steps:

Use the double-dash (--) notation: Simply insert two dashes (--) at the beginning of the line where you want to add the comment. Everything after the dashes will be considered a comment.

Use the hash symbol (#): You can also use the hash symbol (#) to begin a comment. Similar to the double-dash notation, anything after the hash symbol will be treated as a comment.

Use the /* ... / notation: If you have multi-line comments, you can enclose them between / and */. This notation allows you to add comments that span multiple lines.
 

-- This is a single-line comment

# This is also a single-line comment

/* This is a

   multi-line comment */

These methods will help you add comments to your SQL code in MySQL, making it easier for you and other developers to understand and maintain the code in the future.

0 votes
by (8.7k points)
edited by

Comments really help programmers as well as others to easily understand what the code is all about, so MySQL also provides a format to add comments to increase the readability of the program.

Have a look at a different format to add a comment :

  • # adding comment

  • --adding a comment

  • /* adding comment*/

Interested in SQL Server? Here is the SQL Training provided by Intellipaat.
0 votes
by (7.8k points)
To add comments in MySQL SQL code, you can either use the double-dash notation (--) or the hash symbol (#) for single-line comments. Simply insert either of these symbols at the beginning of the line where you want to add the comment. For multi-line comments, you can enclose them between /* and */. These comment notations will help you document your code and provide explanations or clarifications for yourself and other developers working with the code.
0 votes
by (13k points)

Use "--" or "#" for single-line comments, and "/* ... */" for multi-line comments in MySQL SQL code.

Related questions

0 votes
1 answer
asked Jul 15, 2019 in Salesforce by Kartik12234 (11.9k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...