This SQL instructional exercise discloses how to utilize remarks inside your SQL proclamations with linguistic structure and illustrations.In SQL, you can comment like any other procedural programming language. Comments can appear on single line or across multiple lines. Comments are used to explain SQL statements and prevents it from execution. SQL Comments—> single line , multiple line:
Note: SQL Comments are not active in Microsoft Access Databases (Firefox, and Microsoft Edge do not support SQL Comments)
There are two syntax to use Comments in SQL ( SQL Comments).
- Single Line Comments
- Multiple Line Comments
Let us look at some examples and learn the concept of SQL Comments:
Single Line Comments:
Single line comments starts with --
text starting with SQL Single Comments (–) will not be executed and would be discarded. SQL single line comments provides a description and information.
Syntax:
--command;
The following command selects the whole table. (-- Select all)
is a example of single line comment . This part is not included and provides the information about statement.
--Select all: SELECT * FROM india;
Single line comments could be used in many occasions and are really helpful in describing statements,function, objects,etc.
SELECT * FROM india --Select*from padhle;
Multi line Comments:
Multi line comments are same as of its counterpart(Single line comments).part enclosed within the brackets of multi like are not included in the program and are used to provide information.
MLC starts with /* and ends with */
Syntax:
/* comments...............................*/
Example:
SELECT /* Author: padhle.com */ padhle.SQL_harsh FROM padhle
the following command extracts SQL_harsh from padhle table.Multi line comments are inserted inside their default tags. /* Author:padhle.com */ part is excluded and is not a part of cod.
Single line Vs Multi Line (Example):
SELECT padhle.SQL_harsh /* Author: padhle.com */ FROM padhle; or SELECT padhle.SQL_harsh -- Author: padhle.com FROM padhle;
In both the cases comments appears at the end of line . Both the statements gives the same output and text mentioned in those tags are not considered to be any part of SQL code.
Hope that you like SQL comments article. Drop your questions and doubts in the comment section down below .