Site icon DataFlair

SQL Comment – Single line and Multi-line Comment

FREE Online Courses: Enroll Now, Thank us Later!

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

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

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

/* 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 –.

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

Let’s revise the SQL Date Functions 

--Select all:
SELECT * FROM Customers;
SELECT * FROM Customers -- WHERE City='Berlin';
--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

/*Select all the columns
of all the records
in the Customers table:*/
SELECT * FROM Customers;
/*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

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

Exit mobile version