Beginner LevelSQL & MySQL
What is the syntax for single-line and multi-line comments in SQL?
❓ Interview Prompt: Explain SQL comment syntax: single-line (`--` and `#`) and multi-line (`/* ... */`) block comments.
SQL supports both single-line and multi-line comments to document query logic:
•
Single-Line Comment: '-- Comment text' (Requires a space after double-dashes) or '# Comment text' (in MySQL).
•
Multi-Line Block Comment: '/ Comment text spanning multiple lines /'.
Code Implementation Example
sql
-- Single-line comment explaining filter criteria
SELECT id, email
FROM users /* Multi-line inline comment */
WHERE status = 'ACTIVE'; -- Filter active users only💡Documenting query logic with single-line and multi-line comments.
🎯 Interview Key Takeaway
Use single-line and block comments to document complex query logic and business rule constraints.
#SQL#Comments#Syntax#Beginner
Back to all SQL & MySQL Questions→