SQL or Structured Query Language is a language used to read, write, change and manage data inside an RDMS. The SQL provides the comment officially in order to provide descriptions for SQL lines, statements. The SQL comment is not executed by the database server and omitted.
SQL Comment Syntax
SQL provides two different characters in order to create comments. These characters are used to create single line and multiline comments. The single line and inline comment can be created with the double dash
-- sign. The multiline or inline inside comment can be created with the
Single Line Comment
The most basic comment type is single line comment where the complete line is interpreted as a comment. None of the lines is executed as SQL. The single-line comment is created with the double dash at the start of the line.
-- This is a single line comment Select * From Users -- This and the following line are comments too -- Select * From Customers
Inline Comment After SQL
The double dash
-- can be used to create comment after an SQL. This can be useful to explain and describe the SQL at the same line. In the following example the SQL queries executed properly.
Select * From Users -- Select users from Users table Select * From Customers -- Select customers from Customers table Select * From Users -- Where name="ismail"
Inline Comment Inside SQL
The mutiline comments are created using the
/* set start and
*/ set end of the comment. The
*/ are very useful where they can specifically set the start and end of the comment. By using these signs we can create an line comment which do not comment the complete line or rest of the line. In the following example we comment out the
surname from the SQL.
Select name , /* user*/ From Users;
/* is used to set multiline comment start and
*/ is used to set the end of the multiline comment. All characters between
*/ are interpreted as comments.
Select * From Users /* Where name="ismail" Select * From Customers */ Select * From Users -- Where name="ismail"
Multiline Comment with Double Dash
The double dash
-- is created and used for single line comments. But using the double dashes in multiple lines multiline comments can be created.
Select * From Users -- First line of multiline comment -- Second line of multiline comment -- 3rd line of multiline comment Select * From Customers Select * From Users -- Where name="ismail"