SQL Comments

Comments are used to explain the Query in SQl to make the code more readable and easier to understand. Comments can also be used to prevent execution of SQL statements.

There are two types of comments: single-lined and multi-lined.

Single Line Comments :

Single line comments begins with --
Any text between -- the end of the line will be ignored (not executed).
The syntax of the Single Line Comments is −

--Select all:
SELECT * FROM Customer;
   


The following example uses a single-line comment to ignore the end of a line:

SELECT * FROM Customer -- WHERE Address='Mumbai';
   



Multi-line Comments :

Multi-line comments begin with / * and end with * /.
Anny text between / * and * / will be ignored.
The syntax of the Multi Line Comments is −

/*Select all the columns
of all the records
in the Customers table:*/
SELECT * FROM Customer;
   


The following example uses a comment to ignore part of a line:

SELECT CustomerName, /*City,*/ Address FROM Customer;   





Visit :


Discussion


* You must be logged in to add comment.