312-50V10 · 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, a double hyphen (--) begins a single-line comment, causing the database engine to ignore everything after it on that 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
(24 responses)- A88% (21)
- B4% (1)
- D8% (2)
Why each option
In SQL, a double hyphen (--) begins a single-line comment, causing the database engine to ignore everything after it on that line.
The ANSI SQL standard defines -- as the single-line comment delimiter; any text following -- on the same line is ignored by the SQL parser. This syntax is supported across major RDBMS platforms including SQL Server, Oracle, MySQL, and PostgreSQL, and is also commonly exploited in SQL injection attacks to truncate or neutralize the remainder of a query.
|| is the standard SQL string concatenation operator (used in Oracle, PostgreSQL, and ANSI SQL) and has no comment-related function.
%% is not valid SQL syntax; a single % is used as a wildcard character within LIKE predicate patterns, not for comments.
'' represents an empty string literal in SQL and has no comment functionality.
Concept tested: SQL single-line comment syntax and injection
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.