Loading Posts...

How To Add Comments in SQL Query Tutorial With Example

How To Add Comments in SQL Query Tutorial With Example

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:

  1. Single line comments.
  2. Multi-line comments
  3. 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.

 

How To Add Comments in SQL Query Tutorial

#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.

 

Multi-line Comments

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.

Add Comments in SQL
Finally,  How To Add Comments in SQL Query Tutorial With Example is over.

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

Get Free Email Updates!

Signup now and receive an email once I publish new content.

I agree to have my personal information transfered to MailChimp ( more information )

I will never give away, trade or sell your email address. You can unsubscribe at any time.

user

The author didnt add any Information to his profile yet

Loading Posts...