ELEVATE YOUR BUSINESS WITH

Limitless customization options & Elementor compatibility let anyone create a beautiful website with Valiance.

Comments in MySql

SELECT * FROM `itio_tutorial_master` WHERE `tutorial_menu`='7' AND `tutorial_submenu`='63' AND `tutorial_status`=1 LIMIT 1

Comments in MySql

Comments in MySQL

Comments in MySQL are used to add explanations or disable parts of queries without executing them. MySQL supports three types of comments:


1. Single-Line Comments (-- or #)

  • Used for short explanations or debugging.
  • Everything after -- (double hyphen with a space) or # is ignored by MySQL.

Example: Using --

SELECT * FROM employees; -- This fetches all employees

Note: There must be a space after -- (--⎵).
--This is wrong (No space after --)

Example: Using #

SELECT * FROM employees; # This is also a valid comment


2. Multi-Line Comments (/* ... */)

  • Used for long comments or disabling multiple lines of code.

Example: Commenting out a block

/* This query retrieves employees from the IT department only.*/SELECT * FROM employees WHERE department = 'IT';

Example: Disabling a part of a query

SELECT * FROM employees WHERE department = 'IT' /* AND salary > 50000 */ORDER BY employee_name;

✅ The part inside /* ... */ is ignored.


3. Nested Comments (MySQL-Specific)

  • MySQL supports nested comments using /*! ... */.
  • Used for hints or version-specific code.

Example: Executed only in MySQL

SELECT * FROM employees /*! WHERE salary > 50000 */;

✅ Runs as normal SQL in MySQL.
❌ Ignored in other SQL databases.


Best Practices

✅ Use -- for quick inline notes.
✅ Use /* ... */ for long explanations or disabling code.
✅ Avoid excessive commenting in production queries.

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql