Comments — SQL Technical Interview Questions & Answers
Comments
Comments
- -- 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: Comments: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: -- comment and /* block */
Code Examples for Comments
Comments — sample query
-- Comments
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;Comments: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain Comments to an Interviewer
SQL line comment?
-- then a space # also in MySQL