SQL Comments Tutorial with Example – POFTUT

SQL Comments Tutorial with Example

SQL is a defacto language used to manage, query, select, filter data in a relational database. Similar to the programming languages SQL provides comments in order to make the SQL query or clause more readable and put some note.

Single-Line Comments

We will start with single-line comments. Double dash -- is used to create a single line comment. We can put the double dash at the start of the line which we want to comment on.

Inline Comments

We can also use the double dash in order to create half-line or inline comments. We will put a double dash where we want to comment to start. In this example after the SELECT query, we will put a double dash and the next part of the line will become a comment.

We can also use /* and */ in order to create inline comments. /* will specify the start and */ will specify the end of the inline comment.

We can also comment on some SQL parts like below.

We can see that City is commented and it will not returned y the SQL query.

LEARN MORE  How To Create Database and Table In MySQL and MariaDB?

Multi-Line Comments

Another useful comment type is a multi-line comment where we will use /* in order to set the start of the comment and */ for the end of the comment. Lines between /* and */ will be assumed as a comment to like below.

echo '

Here is another example of the multi-line comment.

Nested Comments

Comments can be nested. Nesting comments can be useful when we try some different SQL sentences and enable or disable them by commenting and uncommenting.

Execute Comment In MySQL

MySQL database provides some extensions to the SQL language. We can use executable comments in order to run SQL for specific MySQL versions. e will use /*! for the start and */ for the end of the executable comment. In the following example, we will sum the two values which will return 4.

LEARN MORE  How To Create, Use and Delete SQL View?

Execute Comment For Specific MySQL Version

We can also execute comments for specific MySQL version. We will specify the MySQL version only numbers without dots. and then provide the SQL like below. In the following example, we will run the comment the MySQL version 5.2.10 .

Leave a Reply

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