🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

SQL – Comments

Add explanatory notes to your SQL code using single-line and multi-line comment syntax.

Good SQL code is thoroughly commented, especially in complex stored procedures, views, and multi-join queries. SQL supports two comment styles: single-line comments starting with -- (everything after the dashes is ignored), and multi-line comments enclosed between /* and */.

Comments are invisible to the SQL engine — they exist purely for humans. Use them to explain why a query does something, not just what it does. The “what” is usually apparent from the code; the “why” requires context.

Comment styles

-- This is a single-line comment

SELECT name -- you can comment mid-line too
FROM students;

/*
  This is a multi-line comment.
  Useful for documenting complex logic or
  temporarily disabling blocks of SQL.
*/

Try It Yourself — Interactive SQL Editor

Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.

SQLite – edit & run
Results
← Click Run Query ▶ to see results

Key Points

  • — is the standard single-line comment in all SQL dialects
  • /* */ wraps multi-line comments
  • Comments are stripped by the parser — zero performance impact
  • Use comments to explain business logic, not just repeat the code

Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.

In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.