Home  >  Article  >  Database  >  What are the ways to add comments in MySQL queries?

What are the ways to add comments in MySQL queries?

WBOY
WBOYforward
2023-08-28 11:33:02775browse

What are the ways to add comments in MySQL queries?

We can add comments through several methods supported by MySQL server -

# Comment

This is a single-line comment. Such comments start with the # character and continue until the end of the line.

-– Comment

This is also a single-line comment. Must be followed by a space or control character.

/* Comment */

This is a multi-line comment. This syntax allows comments to be extended to multiple lines because the start and end sequences do not have to be on the same line.

Consider the following example to demonstrate all three types of comments - p>

mysql> Select NOW() #Single line comment continues to the end of line
    -> ;
+---------------------+
| NOW()               |
+---------------------+
| 2017-11-07 15:04:03 |
+---------------------+
1 row in set (0.00 sec)

mysql> Select NOW() -- Single line comment continues to the end of line
    -> ;
+---------------------+
| NOW()               |
+---------------------+
| 2017-11-07 15:04:17 |
+---------------------+
1 row in set (0.00 sec)

mysql> Select 1 /* in-line comment */ +1;
+-------+
| 1 +1  |
+-------+
|     2 |
+-------+
1 row in set (0.10 sec)

mysql> Select 1 /* in-line comment */ +1;
+-------+
| 1 +1  |
+-------+
|     2 |
+-------+
1 row in set (0.00 sec)

mysql> Select 1
    -> /*
   /*> this is a Multiple-line
   /*> comment
   /*> */
    -> +1;
+-------+
| 1  +1 |
+-------+
|     2 |
+-------+
1 row in set (0.00 sec)

The above is the detailed content of What are the ways to add comments in MySQL queries?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete