SQL Comment – Single line and Multi-line Comment
Expert-led Courses: Transform Your Career – Enroll 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.
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
Your opinion matters
Please write your valuable feedback about DataFlair on Google
Aaaa by me
Khurshidbmk reef a by
Thanks for sharing this information . really this is very helpful for ever DBMS operator