sql / beginner
Snippet
Documenting Database Code with Standard SQL Comments
Comments help document SQL queries for readability and maintainability. Standard ANSI SQL supports single-line comments using double hyphens '--' and multi-line comments using '/* ... */'.
snippet.sql
sql
1
2
3
4
-- Retrieve active customer emails for newsletterSELECT emailFROM customersWHERE status = 'ACTIVE'; /* Filter active users only */
Breakdown
1
-- Retrieve active customer emails for newsletter
Uses double hyphens for a single-line comment to describe query intent.
2
SELECT email
Chooses the 'email' column to fetch from matching rows.
3
FROM customers
Specifies the source table 'customers'.
4
WHERE status = 'ACTIVE'; /* Filter active users only */
Filters rows by status and includes an inline multi-line style comment.