Mysql 简明教程
MySQL - Comments
The MySQL Comments
MySQL 注释是添加到代码片段中的文本说明,旨在提供关于代码的更多信息。注释不适合作为代码的一部分执行。它充当注释,让读者(包括开发人员)了解代码的用途、功能或任何其他相关详细信息。
The MySQL Comment is a textual explanation added to a piece of code to provide additional information about the code. Comments are not meant to be executed as part of the code. It serve as notes for readers, including developers, to understand the purpose of the code, functionality, or any other relevant details.
MySQL 中有两种类型的注释: Single-line comments 和 Multi-line comments
There are two types of comments in MySQL: Single-line comments and Multi-line comments
The MySQL Single Line Comments
单行注释用于在单行中进行简要说明。要在 MySQL 中创建单行注释,请使用两个连字符 (--),后跟您的注释文本。
Single-line comments are used for brief explanations on a single line. To create a single-line comment in MySQL, use two hyphens (--) followed by your comment text.
The MySQL Multi-line Comments
MySQL 中的多行注释用于进行较长的说明或注释掉多行代码。这些注释以 / 开始,以 / 结束。它们之间的所有内容都被视为注释。
Multi-line comments in MySQL are used for longer explanations or to comment out multiple lines of code. These comments start with / and end with /. Everything between them is considered a comment.
Where to Place Comments
您几乎可以在您的 SQL 代码中的任何位置放置注释。常见位置包括 −
You can place comments almost anywhere in your SQL code. Common places include −
-
Before or after a SQL statement.
-
Within a SQL statement to explain a specific part of it.
-
At the beginning of a script or stored procedure to describe its purpose.
-- This is a comment before a query
SELECT * FROM orders;
SELECT /* This is an inline comment */ customer_name
FROM customers;
/* This is a comment block at the beginning of a script */
DELIMITER //
CREATE PROCEDURE CalculateDiscount(IN product_id INT)
BEGIN
-- Calculate discount logic here
END //
DELIMITER ;