SQL Comment – Single line and Multi-line Comment

We offer you a brighter future with FREE online courses - Start Now!!

1. Objective – SQL Comment

In our last SQL tutorial, we discussed the SQL Stored Procedure. Today, we will see SQL Comment. Moreover, in this tutorial, we will see the single line and multi-line SQL Comment. Also, we will discuss Comment Indicators in SQL.

So let’s start the SQL Comment tutorial.

SQL Comment - Single line and Multi-line Comment

SQL Comment – Single line and Multi-line Comment

2. What are the Comments in SQL?

SQL Comments are not supported in Microsoft Access databases and thus we use Firefox and Microsoft Edge.

SQL Comment Syntax

The two types of syntax in SQL comment–
Have a look at SQL Sequence

  • SQL Comment Syntax Using — symbol
-- comment goes here

In a line break after it. This method of commenting must be at the end of the line and be in a single line.

  • SQL Comment Syntax Using /* and */ symbols
/* comment goes here */

A comment in SQL that starts with /* symbol and ends with */ and can span several lines within your SQL.

a. SQL Single Line Comment

Single line comments start with –.

  • Example of SQL Single Line Comment

Let’s revise the SQL Date Functions 

--Select all:
SELECT * FROM Customers;
  • Example of SQL Single Line Comment
SELECT * FROM Customers -- WHERE City='Berlin';
  • Example of SQL Single Line Comment
--SELECT * FROM Customers;
SELECT * FROM Products;

b. SQL Multi-line Comment

Multi-line SQL Comments start with /* and end with */ and anything between them would be ignored.
Have a look at SQL Subquery

  • Example of SQL Multi-line Comment
/*Select all the columns
of all the records
in the Customers table:*/
SELECT * FROM Customers;
  • Example of SQL Multi-line Comment
/*SELECT * FROM Customers;
SELECT * FROM Products;
SELECT * FROM Orders;
SELECT * FROM Categories;*/
SELECT * FROM Suppliers;

In SQL if we want to ignore just a part of a statement, we can use the /* */ comment.
To ignore part of a line:
You must read about SQL Null Functions

  • Example of SQL Multi-line Comment
SELECT CustomerName, /*City,*/ Country FROM Customers;

3. SQL Comment Indicators

SQL Comment Indicator is indicated in following examples, including the double hyphen ( — ), braces ( { } ), and C-style ( /* . . . */ ) comment delimiters to include a comment after an SQL statement.

SELECT * FROM customer; -- Selects all columns and rows
SELECT * FROM customer; {Selects all columns and rows}
SELECT * FROM customer; /*Selects all columns and rows*/copy to clipboard
  • In the following examples, we will place the comment on a separate line –
SELECT * FROM customer;
  -- Selects all columns and rows
SELECT * FROM customer;
  {Selects all columns and rows}
SELECT * FROM customer;
  /*Selects all columns and rows*/copy to clipboard

Examples of multi-line statements –
Let’s discuss SQL Operators

SELECT * FROM customer;
  -- Selects all columns and rows
  -- from the customer table
SELECT * FROM customer;
  {Selects all columns and rows
   from the customer table}
SELECT * FROM customer;
  /*Selects all columns and rows
   from the customer table*/copy to clipboard
SELECT *           -- Selects all columns and rows
  FROM customer;  -- from the customer table
SELECT *           {Selects all columns and rows}
  FROM customer;  {from the customer table}
SELECT *           /*Selects all columns and rows*/
  FROM customer;  /*from the customer table*/copy to clipboard

So, this was all in SQL Comment. Hope you liked our explanation.

4. Conclusion – SQL Comment

Hence, in this SQL Comment tutorial, we discussed different comments in SQL. We saw SQL Single line and Multi-Line Comment. Also, we discussed comment indicators in SQL. Is this explanation helps to you, tell us through comments.
See also – 
SQL Cursor
For reference

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

follow dataflair on YouTube

3 Responses

  1. Khurshid mk says:

    Aaaa by me

  2. technvrial says:

    Thanks for sharing this information . really this is very helpful for ever DBMS operator

Leave a Reply

Your email address will not be published. Required fields are marked *