bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL Comments

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind SQL Comments?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

-- ___ all German
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Comments are used to explain SQL code, or to temporarily prevent execution of SQL code (for debugging).
SQL Multi-line Comments
SQL Single-line Comments

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 -- , 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.

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

Example

-- Selects all German
  customers

SELECT * FROM Customers
WHERE Country = 'Germany';

The following example uses a single-line comment to comment away the end of a line:

Example

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

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.

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';

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;

To ignore just a part of an SQL code, you can also use multi-line comment:

Example

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

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