How To Add Comments in SQL Query Tutorial With Example is today’s topic. Comments are used to explain the sections of SQL statements, or to prevent the execution of SQL statements. Comments are not supported in the Microsoft Access databases. Mozilla Firefox and Microsoft Edge are using Microsoft Access database in our examples.
How To Add Comments in SQL
In SQL, you can comment the code just like any other language. Comments can appear on the single line or span across the multiple lines. Let’s explore how to comment on your SQL statements.
Comments can be written in the following formats:
- Single line comments.
- Multi-line comments
- Inline comments
#Syntax
#Syntax Using — Symbol
The syntax for creating the comment in SQL using — symbol is the following.
-- comment goes here
Any text between — and the end of the line will be ignored (will not be executed).
The comment started with — symbol must be at the end of the line in your SQL statement with the line break after it. The above method of commenting can only span the single line within your SQL and must be at the end of the line.
See the following example. If you do not know how to create a table, then check out the article on how to create a table in MySQL.
-- fetch the records staring from LV SELECT * FROM Products WHERE ProductName LIKE 'LV%'
See the following output.

#Multi-line Comments OR Syntax Using /* and */ symbols
See the following query.
/*Select all the columns of all the records in the Products table:*/ SELECT * FROM Products
See the output.

If we want to ignore just the part of the statement, also use a /* */ comment.
See the following example which uses a comment to ignore part of the line.
SELECT ProductName, /*ProductCategory,*/ ProductPrice FROM Products
See the following output.

The post How To Add Comments in SQL Query Tutorial With Example appeared first on AppDividend.