bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL Comments

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.

SQL supports single-line comments

Formula

--, and multi - line comments

/* */.

Note:

Comments are not supported in Microsoft Access databases.

SQL Single-line Comments

Single-line comments start with

-- and continue to the end of line.

Any text after

-- and to the end of the line will be ignored.

Formula

The following example uses a single - line comment as an explanation:

Example

-- 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:

Example

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

Formula

The following example uses a single - line comment to temporarily prevent execution of an SQL statement:

Example

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

SQL Multi-line Comments

Multi-line comments start with

/* and end with */.

Any text between

/* and */ will be ignored.

Formula

The following example uses a multi - line comment as an explanation:

Example

/* 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:

Example

/* 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:

Example

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

Formula

The following example uses a multi - line comment to ignore part of an SQL 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;

Previous

SQL Stored Procedures

Next

SQL Operators