Like most programming languages, SQL lets you write comments — notes in your code that the database engine ignores completely when running the query. They don't affect the result in any way; they exist purely to make a query easier for a human to read later, including a future version of yourself.
Comments become genuinely useful once queries grow past a few lines — explaining why a filter exists, flagging a temporary workaround, or leaving instructions for whoever edits the query next.
Single-Line Comments
A double hyphen -- comments out everything from that point to the end of the line:
-- Get all Engineering employees hired in the last year
SELECT name, hire_date
FROM employees
WHERE department = 'Engineering' -- excludes contractors, see note below
AND hire_date >= '2024-01-01';
Note the trailing comment on the WHERE line — a single-line comment can start anywhere, not just at the beginning of a line, and everything after it on that same line is ignored.
Multi-Line Comments
For longer explanations spanning several lines, wrap the text in /* ... */:
/*
This query powers the "Top Earners" dashboard widget.
Updated 2026-01-15 to exclude interns per finance team request.
If salary thresholds change, update the WHERE clause below.
*/
SELECT name, department, salary
FROM employees
WHERE salary > 80000;
Multi-line comments are also handy for temporarily disabling a chunk of a query while testing, without deleting it:
SELECT name, salary
FROM employees
/* AND department = 'Sales' -- temporarily disabled for testing */
ORDER BY salary DESC;
When Comments Actually Help
Comments are most valuable when they explain why something is written the way it is, not what it does — a query like WHERE department = 'Engineering' is already self-explanatory, but a comment explaining why a seemingly odd condition exists (a business rule, a data quirk, a workaround for a known issue) saves real time for the next person who touches the query. Over-commenting obvious lines just adds clutter without adding understanding.
As your queries start combining WHERE filters, joins, and subqueries, a short comment above each major clause can make the difference between a query that's easy to maintain and one nobody wants to touch six months later.
