MySQL Comments
MySQL Comments
SQL statements can be used with comments to indicate certain parts or to stop them from running.
Single Line Comments
Comments in single lines begin with —.
Anything that appears between — and the end of the line will not be executed and will be ignored.
A single-line comment serves as an explanation in the example that follows:
Example
-- Select all:
SELECT * FROM Customers;
The following example uses a single-line comment to ignore the end of a line:
Example
SELECT * FROM Customers -- WHERE City='Berlin';
The following example uses a single-line comment to ignore a statement:
Example
-- SELECT * FROM Customers;
SELECT * FROM Products;
Multi-line Comments
Comments with multiple lines begin with /* and conclude with */.
Text that is entered between /* and */ will not be read.
A multi-line remark serves as an explanation in the example that follows:
Example
/*Select all the columns
of all the records
in the Customers table:*/
SELECT * FROM Customers;
The following example uses a multi-line comment to ignore many statements:
Example
/*SELECT * FROM Customers;
SELECT * FROM Products;
SELECT * FROM Orders;
SELECT * FROM Categories;*/
SELECT * FROM Suppliers;
You can also use the /* */ comment to ignore a portion of a statement.
In the example below, a portion of a line is ignored using a comment:
Example
SELECT CustomerName, /*City,*/ Country FROM Customers;
The following example uses a comment to ignore part of a statement:
Example
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;