MySQL

How To Comment In MySQL

It may be interesting to insert comments in the SQL queries to better understand them when there are large and complex queries. There are several ways to make comments in the SQL language, depending on the Database Management System (DBMS) used and its version.
 

Double dash comment: – –

The double dash allows you to make a comment until the end of the line.
 
Example :

SELECT *    -- select all
FROM table1 -- in table "table1"

 

 

Comment hash: #

The hash symbol allows you to make a comment until the end of the line.
 
Example :

SELECT *    # select all
FROM table1 # in table "table1"

 

Multi-line comment: /* and */

Multi-line comment has the advantage of being able to indicate where the comment begins and ends. It is therefore possible to use it in the middle of an SQL query without any problem.
 
Example 1

/* This is an example of
multi-line comment which
select all data in "table1" */
SELECT * FROM table1 WHERE 1 = 1;

 
Example 2

SELECT *    /* select all */
FROM table1 /* data in "table1" */
WHERE 1 = /* mid-request example */ 1

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *