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

MySQL Comments


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

MySQL supports single-line comments --, and multi-line comments /* */.

Note: MySQL requires a space after the second dash in a single-line comment!


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

MySQL 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 MySQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

MySQL Comments – FAQs

Quick answers about learning MySQL Comments in MySQL.

This free note from CodingNow 2.0 explains MySQL Comments in MySQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every MySQL topic on CodingNow 2.0, including MySQL Comments, is 100% free with no signup required.
With focused practice, most students grasp MySQL 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