What is the purpose of comments in MySQL?
A
To execute hidden queries
C
To include explanations or notes within SQL code
Analysis & Theory
Comments in SQL are used to add notes or explanations, which are ignored during execution.
Which symbol is used for a single-line comment in MySQL?
Analysis & Theory
MySQL supports `--` (with a space) or `#` for single-line comments.
Which of the following is a valid multi-line comment in MySQL?
A
`/* This is a comment */`
B
`-- This is a comment --`
C
`// This is a comment //`
D
`## This is a comment ##`
Analysis & Theory
`/* ... */` is used for multi-line comments in MySQL.
What will happen if you forget to close a multi-line comment in MySQL?
A
The SQL statement executes normally
B
An error will be thrown
C
The rest of the code will be treated as a comment
D
The query will skip the comment
Analysis & Theory
If you forget to close a multi-line comment (`*/`), the rest of the SQL will be treated as a comment and ignored.
What must follow `--` to correctly start a comment in MySQL?
Analysis & Theory
`--` must be followed by a space or control character to be recognized as a valid comment in MySQL.
Which of the following is NOT a valid way to add a comment in MySQL?
C
/* This is a comment */
Analysis & Theory
`//` is not valid for comments in standard MySQL syntax.
Where can comments be placed in an SQL statement?
C
Only outside the statement
D
Anywhere in the SQL code
Analysis & Theory
Comments can be placed anywhere in the SQL code as long as they follow correct syntax.
What is the output of this SQL?
`SELECT 1 + 1; -- Adds two numbers`
Analysis & Theory
The comment is ignored by MySQL, so the output is just `2`.
How do comments help in SQL code?
A
They improve performance
B
They prevent SQL injection
C
They make the code more readable and maintainable
D
They replace documentation
Analysis & Theory
Comments are useful for explaining SQL code, especially in complex queries.
Which of the following allows you to comment out a block of SQL code for testing?
Analysis & Theory
`/* ... */` is used for multi-line (block) comments to temporarily disable code.