SQL Comments
In SQL, comments are used to leave notes or explanations inside your queries. These comments are ignored when the query runs.
Single-line comment
Start a line with -- (two hyphens):
-- This is a single-line comment
SELECT * FROM employees;
Multi-line comment
Wrap the comment with /* ... */:
/*
This is a multi-line comment.
It spans multiple lines.
*/
SELECT name FROM employees;
Inline comment
You can also write comments inline, between parts of a query. This is helpful for disabling or explaining parts of a statement:
SELECT name /*, age */ FROM employees;
In this case, the age column is commented out and won't be selected.
In our problems, you'll often see comments used to explain what needs to be done. It's a clear way for us to share instructions without affecting how the query runs.