← Back to MySQL Course | Chapter 1: Introduction & Basics | Lesson 8 of 8

MySQL Comments

Single-Line Comments with Double Dash

A double-dash (--) starts a comment that runs to the end of the line, but standard SQL requires a space immediately after the dashes or MySQL may not recognize it as a comment at all.

Example: Single-Line Comments with Double Dash

sql
-- This is a comment
SELECT 1;

Single-Line Comments with Hash

The hash symbol (#) is a MySQL-specific single-line comment marker that behaves like the double-dash but, unlike it, doesn't require a trailing space — a small but easy-to-forget difference between the two styles.

Example: Single-Line Comments with Hash

sql
#This is a MySQL-specific comment
SELECT 1;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Multi-Line Comments

Block comments start with /* and end with */, and can span multiple lines, which makes them the right choice for longer explanations of why a complex query is structured the way it is.

Example: Multi-Line Comments

sql
/* This is a
   multi-line comment */
SELECT 1;

Comments inside SQL Statements

You can drop a block comment mid-statement, right next to a column name or clause, to document exactly what that piece does without breaking the SQL syntax around it.

Example: Comments inside SQL Statements

sql
SELECT name /* the customer's full name */ FROM customers;

Executable Comments

MySQL supports a special executable comment syntax (/*! ... */) that other database systems simply ignore as a normal comment, letting you write MySQL-specific optimizations that stay portable to other engines.

Example: Executable Comments

sql
SELECT /*! SQL_NO_CACHE */ * FROM customers;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.