Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

SQL Comments

SQL Comments

Comments in SQL are utilized either to elucidate sections of SQL statements or to hinder the execution of SQL statements.

Please note that Microsoft Access databases do not support comments.

Single Line Comments

Single line comments in SQL begin with .

Any text following — until the end of the line will be disregarded and not executed.

Below is an example utilizing a single-line comment for clarification:

Example

— Select all:
SELECT * FROM Customers;

In the following example, a single-line comment is employed to disregard the remainder of a line:

Example

SELECT * FROM Customers — WHERE City=’Berlin’;  

In the following example, a single-line comment is used to bypass a statement:

Example

— SELECT * FROM Customers;
SELECT * FROM Products;

Multi-line Comments

Multi-line comments in SQL commence with /* and conclude with */.

Any text enclosed between /* and */ will be disregarded.

Below is an example employing a multi-line comment for clarification:

Example

/*Select all the columns
of all the records
in the Customers table:*/

SELECT * FROM Customers;

In the following example, a multi-line comment is utilized to exclude multiple statements:

Example

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

SELECT * FROM Suppliers;

To disregard only a portion of a statement, employ the /* */ comment.

The subsequent example demonstrates the use of a comment to ignore part of a line:

Example

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

In the following example, a comment is utilized to disregard a portion 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;