How to Add Comments in SQL?
How to Add Comments in SQL
Comments are text notes that are incorporated into the program to make the code easier to understand. In SQL, commenting is used to explain various sections and to provide appropriate documentation to a program. In addition, it also prevents the code from being executed.
Comments can be added in SQL in the following ways:
- Single Line Comment
- Multi Line Comment
- Inline Comment
1. Single Line Comments: Comments which are added to a single line are called as single line comments.
Syntax:
--Add a single line which is to be commented
Example:
SELECT * FROM employee;--Display all the records from employee table
Output:
+--------+----------+------------+ | Emp_ID | Emp_Name | Emp_Salary | +--------+----------+------------+ | 1 | Nikita | 30000 | | 2 | Riddhi | 25000 | | 3 | Nayan | 45000 | | 4 | Shruti | 15000 | | 5 | Anurati | 55000 | +--------+----------+------------+ 5 rows in set (0.00 sec)

“Display all the records from employee table” is displayed as a single line comment in above example, and also not get executed.
2. Multi Line Comment: Comments which are added to multiple lines together are called as multi line comments.
Syntax:
/* Add multiple lines which are to be commented */
Example:
/* Select all the records which are present in employee table */ SELECT *FROM employee;
Output:
+--------+----------+------------+ | Emp_ID | Emp_Name | Emp_Salary | +--------+----------+------------+ | 1 | Nikita | 30000 | | 2 | Riddhi | 25000 | | 3 | Nayan | 45000 | | 4 | Shruti | 15000 | | 5 | Anurati | 55000 | +--------+----------+------------+ 5 rows in set (0.00 sec)

“Select all the records which are present in employee table” is displayed as a multiline comment in above example.
3. Inline Comment: Comments which are added in between the SQL statements are called as inline comments.
Syntax:
SQL Statements /*single or multiple lines which are to be commented*/ continuation of SQL Statements
Example:
SELECT Emp_ID, /*Emp_Name*/ Emp_Salary FROM employee;
- Output:
+--------+------------+ | Emp_ID | Emp_Salary | +--------+------------+ | 1 | 30000 | | 2 | 25000 | | 3 | 45000 | | 4 | 15000 | | 5 | 55000 | +--------+------------+ 5 rows in set (0.00 sec)

“single or multiple lines which are to be commented” is displayed as an inline comment in above example.