312-50V11 · Question #342
Which of the following is used to indicate a single-line comment in structured query language (SQL)?
The correct answer is A. --. In SQL, the double hyphen (--) is the ANSI-standard delimiter for a single-line comment, causing the parser to ignore all text following it on the same line.
Question
Which of the following is used to indicate a single-line comment in structured query language (SQL)?
Options
- A--
- B||
- C%%
- D''
How the community answered
(29 responses)- A86% (25)
- B3% (1)
- C3% (1)
- D7% (2)
Why each option
In SQL, the double hyphen (--) is the ANSI-standard delimiter for a single-line comment, causing the parser to ignore all text following it on the same line.
The double hyphen (--) is defined by the ANSI SQL standard as the single-line comment syntax; every character after -- on that line is ignored by the SQL engine at parse time. This syntax is also commonly exploited in SQL injection attacks to truncate and neutralize the remainder of a query.
The double pipe (||) is the SQL string concatenation operator used to join two string expressions and has no role as a comment delimiter.
The percent sign (%) serves as a wildcard in SQL LIKE predicates; double percent (%%) has no defined meaning as a comment syntax in standard SQL.
Two consecutive single quotes ('') represent an escaped single-quote character or an empty string literal in SQL and are not treated as a comment delimiter.
Concept tested: SQL single-line comment syntax
Source: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/comment-transact-sql
Topics
Community Discussion
No community discussion yet for this question.