Basic about Comments – using and example

This SQL tutorial explains how to use remarks within your SQL statements with syntax and examples.

Description

In SQL, you can comment your code just like any different language. Comments can show up on a single line or span across a couple of lines. Let’s discover how to comment your SQL statements.

Syntax

There are two syntaxes that you can use to create a remark in SQL.

Syntax Using — symbol

The syntax for creating a remark in SQL the usage of — image is:

-- comment goes here

A comment commenced with — image ought to be at the quit of a line in your SQL declaration with a line wreck after it. This technique of commenting can only span a single line within your SQL and have to be at the cease of the line.

Syntax Using /* and */ symbols

The syntax for developing a comment in SQL the usage of /* and */ symbols is:

/* comment goes here */

A comment that starts with /* image and ends with */ and can be somewhere in your SQL statement. This technique of commenting can span countless lines inside your SQL.

Example – Comment on a Single Line

Let’s seem at an instance that suggests how to create a remark in SQL that is on a single line.

For example:

Here is a remark that appears on its own line in SQL:

SELECT websites.site_name
/* Author: TechOnTheNet.com */
FROM websites;

Here is a comment that appears in the middle of the line in SQL:

SELECT  /* Author: TechOnTheNet.com */  websites.site_name
FROM websites;

Here is a comment that seems at the cease of the line in SQL:

SELECT websites.site_name  /* Author: TechOnTheNet.com */
FROM websites;

or

SELECT websites.site_name  -- Author: TechOnTheNet.com
FROM websites;

Example – Comment on Multiple Lines

You can also create a comment that spans multiple lines in your SQL statement.

For example:

SELECT websites.site_name
/*
 * Author: TechOnTheNet.com
 * Purpose: To show a comment that spans multiple lines in your SQL statement.
 */
FROM websites;

This comment spans throughout multiple traces in SQL and in this example, it spans across 4 lines.

You can additionally create a remark that spans more than one strains using this syntax:

SELECT websites.site_name /* Author: TechOnTheNet.com
Purpose: To show a comment that spans multiple lines in your SQL statement. */
FROM websites;

SQL will count on that the whole lot after the /* image is a comment till it reaches the */ symbol, even if it spans more than one lines within the SQL statement. So in this example, the remark will span throughout two lines.