Use annotations in SQL Server

This article will show you how to use annotations in SQL Server statements.

This article will show you how to use annotations in SQL Server statements.

Describe

SQL Server allows you to put comments next to statements for commenting, memorization and further explanation. These comments may appear on a line or spread across multiple lines in the work screen.

Syntax using annotation

There are two syntaxes that can be used to create comments in SQL statements:

Use notation -

Usage is as follows:

 -- chú thích tại đây 

In SQL Server, comments that begin with a symbol - must be at the end of the statement and force a line break after the end of the comment.

Use the symbol / * and * /

Usage is as follows:

 /* chú thích tại đây */ 

In SQL Server, the annotation begins with the symbol / * and ends with * / can be used anywhere in the SQL statement. This comment may extend over several lines.

For example, comment one line

A line comment may appear in many different ways. It can be in the middle of a command or end of a statement, even lying on a single line. Specifically, we can follow the following examples:

Comments appear in the middle of the command:

 SELECT / * Author: quantrimang.com * / employee_id, last_name 
FROM employees;

Annotation appears at the end of the command:

 SELECT employee_id, last_name / * Author: quantrimang.com * / 
FROM employees;

Or:

 SELECT employee_id, last_name - Author: quantrimang.com 
FROM employees;

Annotation is located on a single line:

 SELECT employee_id, last_name 
/ * Author: quantrimang.com * /
FROM employees;

For example, the caption extends across multiple lines

In SQL Server, you can write comments and comments on multiple lines while using SQL statements. An example is as follows:

 SELECT employee_id, last_name 
/ *
* Author: quantrimang.com
* Purpose: Displays annotations spread across multiple lines in an SQL statement
* /
FROM employees;

The caption of the recently executed example is on the four lines of the working screen.

Or you can use this syntax:

 SELECT employee_id, last_name / * Author: quantrimang.com 
Purpose: Displays annotations spread across multiple lines in an SQL statement. * /
FROM employees;

Marking and commenting next to a statement by annotation makes it easy to understand and control, as well as to fix errors for your work more quickly and conveniently.

Good luck!

Previous article: Find User in SQL Server

Next lesson: LITERAL (Hang) in SQL Server

3.5 ★ | 4 Vote