搜索
MySQL 教程 / 注释

注释

MySQL 注释

注释用于解释 SQL 语句的部分,或阻止 SQL 语句的执行。


单行注释

单行注释以--开头。

任何介于 -- 和行尾之间的文本都将被忽略(不会被执行)。

以下示例使用单行注释作为解释:

实例

-- Select all: SELECT * FROM Customers;
»

以下示例使用单行注释来忽略行尾:

实例

SELECT * FROM Customers -- WHERE City='Berlin';
»

以下示例使用单行注释来忽略语句:

实例

-- SELECT * FROM Customers; SELECT * FROM Products;
»


多行注释

多行注释以 /* 开头并以 */ 结尾。

/* 和 */ 之间的任何文本都将被忽略。

以下示例使用多行注释作为解释:

实例

/*Select all the columns of all the records in the Customers table:*/ SELECT * FROM Customers;
»

以下示例使用多行注释来忽略许多语句:

实例

/*SELECT * FROM Customers; SELECT * FROM Products; SELECT * FROM Orders; SELECT * FROM Categories;*/ SELECT * FROM Suppliers;
»

要忽略语句的一部分,也可以使用 /* */ 注释。

以下示例使用注释来忽略行的一部分:

实例

SELECT CustomerName, /*City,*/ Country FROM Customers;
»

以下示例使用注释来忽略部分语句:

实例

SELECT * FROM Customers WHERE (CustomerName LIKE 'L%' OR CustomerName LIKE 'R%' /*OR CustomerName LIKE 'S%' OR CustomerName LIKE 'T%'*/ OR CustomerName LIKE 'W%') AND Country='USA' ORDER BY CustomerName;
»