SQL Comment Styles: Single-Line, Block, and Header Documentation
By Sharon Ben-Moshe · October 12, 2026 · 1 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Discover best practices for writing clean SQL comments. Master single-line (--) dashes, block (/* */) comments, header blocks, and inline explanations.
Quick answer
SQL supports two comment formats: single-line comments starting with two hyphens followed by a space ('-- comment') and multi-line block comments enclosed between '/*' and '*/'. Use block comments for file header documentation and single-line comments on their own preceding lines to explain 'why' a query filter or join condition exists.
FAQs
Why is a trailing space required after '--' in SQL?
The ANSI SQL standard requires a whitespace character immediately following the two dashes (`-- `). While some engines tolerate `--comment` without a space, others treat it as a syntax error or a token operator.
Can block comments be nested in SQL?
PostgreSQL and SQLite support nested block comments (`/* outer /* inner */ outer */`). However, MySQL and SQL Server do not support nested block comments and will throw syntax errors when encountering the first closing `*/`.
Do SQL comments impact query performance?
No. The SQL parser strips comments during lexical analysis before compiling the query plan. However, comments inside dynamic SQL strings do increase network payload size.
Where should inline comments be placed in formatted SQL?
Place comments on their own line immediately preceding the code they document. Placing comments at the end of code lines often causes automated formatters to wrap lines awkwardly.
Keep reading
Building an Enterprise SQL Style Guide: Formatting Standards, Linting, and Team Conventions
By Sharon Ben-Moshe · Oct 13, 2026
The complete blueprint for an enterprise SQL style guide. Standardize formatting, keyword casing, indentation, naming conventions, and CI linting.
Read postThe Master Guide to SQL Common Table Expressions (CTEs): Syntax, Optimization Fences, and Recursion
By Sharon Ben-Moshe · Oct 13, 2026
The definitive guide to SQL Common Table Expressions (CTEs). Master chaining, recursive hierarchies, data-modifying CTEs, and optimization fences.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.