Commenting in SQL means adding single-line or multi-line annotations that the database ignores but humans read for context, debugging, and collaboration.
Learn single-line, multi-line, and database-specific comment syntax, plus Galaxy shortcuts and best practices.
Commenting in SQL adds explanatory text that the database engine skips during execution. Comments improve readability, document business logic, and help teams debug queries without altering results.
Developers comment SQL to record intent, flag TODOs, mark temporary changes, and onboard new teammates. Well-placed comments reduce misunderstandings and cut maintenance time.
Use two dashes (--
) followed by text. Everything after --
until the line break is ignored by the engine.-- return newest orders
SELECT * FROM orders ORDER BY created_at DESC;
Wrap text between /*
and */
. The engine skips all characters inside, even across lines./*
Join orders and customers
Filter to last 30 days only
*/
SELECT ...
PostgreSQL, MySQL, SQLite, SQL Server, and Oracle accept --
and /* */
. SQL Server also supports //
inside its CLI, while BigQuery supports #
. Always check vendor docs for edge cases.
Most engines reject nested /* */
comments. Attempting to close an inner block early throws a syntax error. Use single-line --
for inner notes instead.
Galaxy’s SQL editor toggles comments with ⌘ / (Mac) or Ctrl / (Win/Linux). Select lines and trigger the shortcut to prepend or remove --
. Multi-line blocks auto-wrap in /* */
when multiple lines are selected.
Keep comments concise, action-oriented, and up-to-date. Document why a query exists, not what obvious SQL already shows. Use consistent terminology and include ticket links for traceability.
Avoid disabling critical filters without a TODO, leaking credentials in comments, and using nested block comments. Also, remember comments remain in query logs—sanitize sensitive data.
/* revenue_growth.sql
Computes MoM revenue for dashboards
Owner: data-eng@acme.com */
WITH monthly AS (
SELECT DATE_TRUNC('month', paid_at) AS month,
SUM(amount) AS revenue
FROM payments -- includes refunds already netted
WHERE status = 'paid'
GROUP BY 1
)
SELECT month,
revenue,
revenue - LAG(revenue) OVER (ORDER BY month) AS mom_growth
FROM monthly;
Commenting is crucial because SQL often powers business-critical dashboards and ETL pipelines. Clear annotations prevent misinterpretation, reduce onboarding time, and speed up debugging. In collaborative environments, comments paired with version control and tools like Galaxy enable teams to share context without leaving the editor.
No. The SQL parser strips comments before planning, so performance is unchanged.
Select multiple lines and press ⌘ / (Mac) or Ctrl / (Win/Linux). Galaxy toggles --
on each line or wraps the selection in /* */
.
Comments in ad-hoc queries exist only in logs or saved files. However, comments in database objects like views are stored with the object definition.
Most engines allow UTF-8, so emojis render, but avoid them in production code for professionalism and compatibility.