Comments in SQL are used to annotate SQL code for better understanding and maintenance. They are not executed by the database engine and are solely for human readability.
Single-Line Comments
Single-line comments start with --
and continue until the end of the line. They are useful for adding short explanations to individual lines or queries.
Multi-Line Comments
Multi-line comments start with /*
and end with */
. They can span multiple lines and are suitable for longer explanations or commenting out blocks of code.
Example
-- This is a single-line comment
/*
This is a multi-line comment.
It can span multiple lines.
*/
SELECT * FROM employees; -- Another single-line comment
Comments in SQL help improve code readability, make it easier to understand the purpose of queries, and facilitate collaboration among developers.