How to Comment — SQL Technical Interview Questions & Answers
How to Comment
How to Comment
- -- this is a line comment (space after --). # also works in MySQL. /* block comment */ can span lines.
- Don’t put secrets in comments in dumps. Nested /* */ can surprise you.
- Trap: --comment without a space after -- in some clients.
- On the example next to this theory: How to Comment: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: -- comment and /* block */
Code Examples for How to Comment
How to Comment — sample query
-- How to Comment
CREATE TABLE demo (
id INTEGER PRIMARY KEY,
label TEXT NOT NULL,
qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
(1, 'alpha', 2),
(2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;How to Comment: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain How to Comment to an Interviewer
SQL line comment?
-- then a space # also in MySQL