Home > Database > Mysql Tutorial > What does -- mean in mysql

What does -- mean in mysql

WBOY
Release: 2022-03-02 15:20:03
Original
4776 people have browsed it

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:

#注释内容
Copy after login

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

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

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:

-- 注释内容
Copy after login

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;
Copy after login

# 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:

/*
  第一行注释内容
  第二行注释内容
*/
Copy after login

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;
Copy after login

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;
Copy after login

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

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template