SQL Comments

Comments in SQL are notes added to a query that the database engine ignores when executing it - used to explain what a query does, leave reminders, or temporarily disable a line of code.

Single-Line Comments

-- This query fetches all customers from Noida
SELECT * FROM customers WHERE city = 'Noida';

Multi-Line Comments

/* This query joins customers and orders
   to calculate total spending per customer */
SELECT c.first_name, SUM(o.amount) AS total_spent
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.first_name;

Why Comments Matter

  • Make complex queries easier for others (and future you) to understand
  • Document the purpose and assumptions behind a query
  • Useful for temporarily disabling part of a query while debugging

You've Completed This Section

This wraps up the SQL and database fundamentals - from understanding what a database is and the relational model behind it, through designing structure with ER diagrams, to writing the core SQL statements (CREATE, SELECT, UPDATE, DELETE) that every data professional relies on daily.

Well-commented SQL is especially valuable in team environments and data pipelines, where queries are often revisited and modified months after they were first written.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course