Home  >  Article  >  Database  >  What does -- mean in mysql

What does -- mean in mysql

WBOY
WBOYOriginal
2022-03-02 15:18:154588browse

In mysql, "--" is a comment character, which means a single-line comment. A space comment needs to be added after the comment character to take effect. The syntax is "-- comment content"; this comment character is the same as " The #" comment character is used for single-line comments. The difference is that there is no need to add a space after the "#" comment character.

What does -- mean in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

What does -- mean in mysql

MySQL single-line comments

1) Single-line comments can use the #comment character, add directly after the #comment character Annotation content. The format is as follows:

#注释内容

Examples of single-line comments using the comment character # are as follows:

#从结果中删除重复行
SELECT DISTINCT product_id, purchase_price FROM Product;

2) Single-line comments can use the -- comment character. A space must be added after the -- comment character before the comment can Take effect. The format is as follows:

-- 注释内容

An example of using the comment character -- in a single-line comment is as follows: The difference between

-- 从结果中删除重复行
SELECT DISTINCT product_id, purchase_price FROM Product;

# and -- is that the comment content is added directly after #, and the second of -- A dash must be followed by a space to add comment content.

MySQL multi-line comments

Multi-line comments use /* */ comment symbols. /* is used for the beginning of the comment content, */ is used for the end of the comment content. The multi-line comment format is as follows:

/*
  第一行注释内容
  第二行注释内容
*/

The comment content is written between /* and */ and can span multiple lines.

Usage examples of multi-line comments are as follows

/*这条SELECT语句,
  会从结果中删除重复行*/
SELECT DISTINCT product_id, purchase_price FROM Product;

Any comment (single-line comment and multi-line comment) can be inserted in the SQL statement, and the comment can be placed anywhere in the SQL statement.

Insert a single-line comment in the SQL statement, as shown below:

SELECT DISTINCT product_id, purchase_price
-- 从结果中删除重复行。 
FROM Product;
SELECT DISTINCT product_id, purchase_price
#从结果中删除重复行。 
FROM Product;

Insert a multi-line comment in the SQL statement, as shown below:

SELECT DISTINCT product_id, purchase_price
/* 这条SELECT语句,  
    会从结果中删除重复行。*/ 
    FROM Product;

Comments can be written in any SQL statements, and there is no limit on the number of comments in a SQL statement.

Recommended learning: mysql video tutorial

The above is the detailed content of What does -- mean in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn