Loading lesson path
Overview
Comments are used to explain SQL code, or to temporarily prevent execution of SQL code (for debugging). Comments are ignored by the database engine.
Formula
--, and multi - line comments/* */.
Comments are not supported in Microsoft Access databases.
-- and continue to the end of line.
-- and to the end of the line will be ignored.
Formula
The following example uses a single - line comment as an explanation:-- Selects all German customers
SELECT * FROM Customers
WHERE Country = 'Germany';Formula
The following example uses a single - line comment to comment away the end of a line:SELECT * FROM Customers -- WHERE City='Berlin';Formula
The following example uses a single - line comment to temporarily prevent execution of an SQL statement:-- SELECT * FROM Customers;
SELECT * FROM Products;/* and end with */.
/* and */ will be ignored.
Formula
The following example uses a multi - line comment as an explanation:/* Selects all German customers from Berlin */
SELECT * FROM Customers
WHERE Country = 'Germany' AND City = 'Berlin';Formula
The following example uses a multi - line comment to ignore many SQL statements:/* SELECT * FROM Customers;
SELECT * FROM Products;
SELECT * FROM Orders;
SELECT * FROM Categories; */
SELECT * FROM Suppliers;Formula
To ignore just a part of an SQL code, you can also use multi - line comment:SELECT CustomerName, /*City,*/ Country FROM Customers;Formula
The following example uses a multi - line comment to ignore part of an SQL statement: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;