W3. SQL Comments Flashcards
Q: What is the purpose of comments in SQL?
A: Comments explain sections of SQL statements or prevent execution of specific code parts.
Q: Are comments supported in Microsoft Access databases?
A: No, comments are not supported in Microsoft Access databases.
Q: How do you write a single-line comment in SQL?
A: Use –, followed by the comment text.
Q: Write a single-line comment to explain “Select all” before a SQL query.
– Select all:
SELECT * FROM Customers;
Q: How can you use a single-line comment to ignore part of a SQL statement?
A: Place – after the code you want to execute, e.g.,
SELECT * FROM Customers – WHERE City=’Berlin’;
Q: How do you write a multi-line comment in SQL?
A: Wrap the text with /* and */.
Q: Write a multi-line comment to describe a SQL query that selects all records from Customers.
/*
Select all the columns
of all the records
in the Customers table:
*/
SELECT * FROM Customers;
Q: How can you use multi-line comments to ignore multiple SQL statements?
A: Place /* before and */ after the statements, e.g.,
/*
SELECT * FROM Customers;
SELECT * FROM Products;
*/
Q: Write a query that uses a comment to ignore part of a line in a SELECT statement.
SELECT CustomerName, /City,/ Country FROM Customers;
Q: Write a query that uses a comment to ignore part of a condition in a WHERE clause.
SELECT * FROM Customers
WHERE (CustomerName LIKE ‘L%’
OR CustomerName LIKE ‘R%’ /* OR CustomerName LIKE ‘S%’
OR CustomerName LIKE ‘T%’ */
OR CustomerName LIKE ‘W%’)
AND Country=’USA’
ORDER BY CustomerName;