Python SQL Comments: Single-Line (--), Multi-Line (/* */) & Query Hints
Comments explain business logic, document complex joins, and temporarily disable clauses during query debugging. Standard SQL supports single-line comments starting with `--` and multi-line block comments enclosed between `/*` and `*/`.
"Comments are like sticky notes left on a blueprint: they guide future developers and maintenance engineers without altering the physical building structure."
Deep Dive: How It Works
Single-Line Comments: `-- This is ignored until the end of the line`.
Multi-Line Block Comments: `/* Multi-line explanation or disabled code block */`.
Optimizer Query Hints: In database engines like MySQL (`/*+ INDEX(users idx_email) */`) and Oracle, special comment blocks provide execution directives to the query planner.
Syntax Blueprint
-- Single line comment SELECT id, name /* inline comment */ FROM users /* Multi-line documentation block */ WHERE active = 1;
Use -- for quick notes and /* */ for multi-line documentation.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Accidentally leaving a `--` comment inside a dynamic SQL string without a trailing newline before the next clause.Why it happens: The remainder of the dynamic query gets commented out on the same line.
How to fix: Ensure newlines separate query lines when generating SQL programmatically.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Write a Query with Comments
Add a single-line comment `-- Query active users` and run `SELECT name FROM clients;`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.