Geek Slack

Getting Started with SQL Server
About Lesson


SQL Comments


SQL Comments

In SQL, comments are used to annotate SQL code for better understanding and documentation. Comments are ignored by the SQL engine during execution.

Single-line Comments

SELECT * FROM Employees; -- This is a single-line comment

This is a single-line comment that follows a SQL statement.

Multi-line Comments

/*
This is a multi-line comment
that spans across multiple lines
*/

This is a multi-line comment enclosed within /* and */ delimiters.

Comments within SQL Statements

SELECT
    /* Selecting all columns */
    * 
FROM
    Employees;

This example demonstrates a comment within a SQL statement, providing additional context about the query.

Usage Notes

  • Comments in SQL are essential for documenting code, explaining logic, and improving readability.
  • Single-line comments start with --, and multi-line comments are enclosed within /* and */ delimiters.
  • Comments should be concise and relevant to the code they annotate.
  • Comments are ignored by the SQL engine during execution, so they do not affect query performance.

Join the conversation