English 中文(简体)
SQL Tutorial

5. 图瓦卢

Selected Reading

SQL - Comments
  • 时间:2024-12-27

SQL - Comments


Previous Page Next Page  

In Programming, a comment is a technique to hide a pne of code from the compiler. It is also defined as an annotation and program-readable explanation of a computer program, added with the purpose of making the source code easier for humans to understand in a better way.

SQL-Comments

Comments are used to explain the section of the SQL statement; or to stop the execution of the statement. So, whenever a pne(s) of code is marked as a comment in a program, it is not executed.

Let us say we are performing a SQL query to display the contents of a table. But if the user does not understand the query, then we can utipze the comments to explain the idea or the query.

There are three types of comments in SQL, let’s see them in detail −

    Single-pne comment.

    Multi-pne comment.

    In pne comment.

Single-pne comment

A single pne comment is one that ends in a single pne and begins with — (double hyphen), and the text after the — (double hyphen) is not executable.

Syntax

Following is the syntax of the single-pne comment.


--fetch all the table details
--another comment.
--SQL SELECT Query.
SELECT * from table_name

Multi-pne comment

A multi-pne comment is a text that starts in one pne and ends in different pne, as well as text which is between these (/*…. */) symbols is known as multipne comment.

Syntax

Following is the syntax of the multi-pne comment.


/* this is first comment
This is second comment
Multi pne comment*/
SELECT * FROM table_name;

Inpne-comment

An inpne comment is the same as a multipne comment that is enclosed between /* and /*; but, an inpne comment is one that is present at the same pne where the SQL query is provided.

Syntax

Following is then syntax of the inpne comment.


SELECT * FROM table_name; /*customers*/

Example

In the following example, we define a SQL query that will create a table and display its contents, as well as provide all types of comments to explain the query in a better way.


--CREATING A TABLE
CREATE TABLE Customerss(ID INT NOT NULL, NAME VARCHAR(50), AGE INT NOT NULL);
/* INSERTING COLUMN S VALUE 
IN A TABLE NAMELY CUSTMERS */
INSERT INTO Customerss VALUES(01,  Tutorialspoint , 10);
INSERT INTO Customerss VALUES(02,  Tutorix , 03);
SELECT * FROM Customerss; /* DISPLAYING TABLE DETAILS */

When we run the above SQL query, we get the column values, however the comment pne is not executable, as we can see in the table below −


+----+----------------+-----+
| ID | NAME           | AGE |
+----+----------------+-----+
|  1 | Tutorialspoint |  10 |
|  2 | Tutorix        |   3 |
+----+----------------+-----+
Advertisements