Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to SQL Notes
Topic #105

SQL Comments — Single-Line and Multi-Line

SQL comments let you document a query or temporarily disable part of it without deleting code. They're ignored by the database engine.

Single-Line Comments

-- This gets every employee earning above 50,000
SELECT * FROM employees WHERE salary > 50000;

Everything from -- to the end of the line is ignored. Note: standard SQL requires a space after --.

Multi-Line Comments

/* This query powers the monthly payroll report.
   Do not remove the status filter — finance relies on it. */
SELECT name, salary
FROM employees
WHERE status = 'active';

Dialect Note: The # Symbol

MySQL only also supports # for a single-line comment:

# MySQL-specific single-line comment
SELECT * FROM employees;

PostgreSQL and SQL Server do not support # as a comment marker — stick to -- for anything you want to be portable across databases.

Practical Use Cases

  • Explaining why a query filters a certain way (business context a future reader won't guess)
  • Temporarily commenting out a clause while debugging a large query
  • Leaving a TODO for a report that needs revisiting

Common Mistake

Over-commenting obvious code (e.g. -- select the name column above SELECT name). Comment the business reason, not the syntax — the syntax is already readable.

Interview Relevance

Rarely asked directly, but expect to be judged on whether your interview SQL is readable — a well-placed comment on a non-obvious filter can make a good impression during a live SQL round.

Practice Question

Add a one-line comment explaining why this filter exists: WHERE order_date >= '2024-01-01' AND status != 'cancelled'

Related SQL Notes

Want to go beyond the notes?

Join CodingNow's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →