SQL Tutorial

SQL Tutorial SQL Introduction SQL Syntax SQL OPERATORS SQL COMMANDS SQL Queries

SQL Table

SQL TABLE SQL CREATE TABLE SQL ALTER TABLE SQL DELETE SQL TRUNCATE TABLE SQL UPDATE TABLE

SQL SELECT

SQL SELECT Statement SQL SELECT IN Operator SQL BETWEEN Operator SQL SELECT BETWEEN Operator SQL SELECT AND Operator SQL SELECT DISTINCT SQL SELECT SUM SQL SELECT MAX SQL SELECT MIN SQL SELECT AVG

SQL Clause

SQL GROUP BY CLAUSE SQL ORDER BY Clause SQL HAVING Clause

SQL INSERT

SQL INSERT INTO Statement

SQL JOIN

SQL JOIN SQL Inner Join SQL Left Join SQL Right Join

SQL OPERATOR

SQL Comparison SQL LOGICAL Operator SQL Arithmetic

Difference

SQL vs NOSQL WHERE vs HAVING DELETE vs DROP GROUP BY vs ORDER BY DROP vs TRUNCATE SQL IN vs SQL EXISTS

MISC

SQL SubQuery SQL CASE Commit and Rollback in SQL Pattern Matching in SQL DDL Commands in SQL DML Commands in SQL Types of SQL Commands SQL COUNT SQL Primary Key SQL FOREIGN KEY SET Operators in SQL Check Constraint in SQL SQL EXCEPT SQL VIEW SQL WHERE Statement SQL CRUD Operation Where Condition in SQL TCL Commands in SQL Types of SQL JOINS SQL Nth Highest Salary SQL NOT OPERATOR SQL UNION ALL SQL INTERSECT SQL Data Definition Language SQL Data Manipulation Language SQL Data Control Language SQL CONSTRAINTS SQL KEYS Codd’s Rules in SQL What is SQL Injection? Trigger In SQL SQL WHERE Multiple Conditions Truncate function in SQL

How To

How to use the BETWEEN operator in SQL How To Use INNER JOIN In SQL How to use LIKE in SQL How to use HAVING Clause in SQL How to use GROUP BY Clause in SQL How To Remove Duplicates In SQL How To Delete A Row In SQL How to add column in table in SQL ? How to drop a column in SQL? How to create a database in SQL? How to use COUNT in SQL? How to Create Temporary Table in SQL? How to Add Foreign Key in SQL? How to Add Comments in SQL? How To Use Group By Clause In SQL How To Use Having Clause In SQL How To Delete Column In Table How To Compare Date In SQL

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:

  1. Single Line Comment
  2. Multi Line Comment
  3. 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) 
Add Comments in SQL

“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) 
Add Comments in SQL

“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) 
Add Comments in SQL

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



ADVERTISEMENT
ADVERTISEMENT