Advertisement
Google Ad Slot: content-top
MySQL Comments
MySQL Comments
In MySQL, comments are used to add notes or explanations within your SQL code. Comments are ignored by the database engine and are solely for developers to make the code easier to read and understand.
Types of Comments in MySQL
MySQL supports three types of comments:
- Single-line Comments using
-- - Single-line Comments using
# - Multi-line Comments using
/* ... */
Single Line Comments
- Use
--(two hyphens) followed by a space for a single-line comment. - It is often used for in-line documentation.
Single-line Comments Using #
#is another way to add single-line comments in MySQL.- This style is common in MySQL scripts.
Note
# comments are not part of the SQL standard, but they work in MySQL.
Multi-line Comments
- Use
/*to start the comment and*/to end it. - Suitable for large comments or when commenting out blocks of SQL code.
When to Use Comments
- To explain the purpose of a query.
- To add notes about changes or updates.
- To temporarily disable parts of a query for debugging.
- To describe complex joins, subqueries, or calculations.