THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Comments


Comments can be used to explain sections of SQL statements.

Comments can also be used to prevent execution, when testing alternative SQL statements.


Note: Comments in SQL statements are not allowed in Microsoft Access Databases.

Single Line Comments

Single line comments start with --.

Any line between -- and the end of the line will be ignored (will not be executed).

Example

A single-line comment as an explanation:

--Select all:
SELECT * FROM Customers;
Try it Yourself »

Example

A single-line comment to ignore the end of a line:

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

Example

A single-line comment to ignore a statement:

--SELECT * FROM Customers;
SELECT * FROM Products;
Try it Yourself »

Multi-line Comments

Multi-line comments start with /* and end with */.

Any text between /* and */ will be ignored.

Example

A multi-line comment as an explanation:

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

Example

A multi-line comment to ignore many statements:

/*SELECT * FROM Customers;
SELECT * FROM Products;
SELECT * FROM Orders;
SELECT * FROM Categories;*/
SELECT * FROM Suppliers;
Try it Yourself »

Comments in Statements

To ignore just a part of a statement, use the /* */ comment.

Any text between /* and */ will be ignored.

Example

Ignore part of a line:

SELECT CustomerName, /*City,*/ Country FROM Customers;
Try it Yourself »

Example

Ignore parts of a statment:

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;
Try it Yourself »