Beginner

156. SQL Comments

Learn how comments are used to document SQL queries and explain logic.

📘 Lesson 156 of 728 ⏱ 7 min 🎯 Beginner

SQL comments are notes written inside SQL code that are ignored by the database when the statement is executed. Single-line and multi-line comment syntax is commonly supported.

Comments make SQL code easier to understand, maintain, review, and troubleshoot.

An analyst can add a comment explaining why a particular filter or business rule is used.

SQL
-- Get active employees
SELECT
    EmployeeName,
    Department
FROM Employees
WHERE Status = 'Active';

Comments are useful in reporting queries, ETL scripts, stored procedures, database development, and team collaboration.

  • Comments document SQL code.
  • Comments are ignored during execution.
  • -- is commonly used for single-line comments.
  • /* */ is commonly used for multi-line comments.
  • Comment syntax can have minor platform differences.
Why are SQL comments used?

SQL comments explain query logic and make code easier to understand and maintain.

What is a common single-line SQL comment syntax?

Two hyphens, --, are commonly used to begin a single-line SQL comment.

Have you finished this lesson?

Introduction to SQL – All Lessons