🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to SQL Notes
Topic #45

SQL Comments


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

Want to go beyond the notes?

Join CodingNow 2.0's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

SQL Comments – FAQs

Quick answers about learning SQL Comments in SQL.

This free note from CodingNow 2.0 explains SQL Comments in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on CodingNow 2.0, including SQL Comments, is 100% free with no signup required.
With focused practice, most students grasp SQL Comments in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now