Clear, practical technology insights About · Contact

Use Annotations in SQL Server: Explained

Understand Use Annotations in SQL Server with clear explanations, practical examples, and useful tips. This updated guide covers the essential concepts and...

Published: 4 minutes read
Table of Contents

Use Annotations in SQL Server is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.

This guide 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 help 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.

As an 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; 

As an 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; 

Next lesson: LITERAL (Hang) in SQL Server

Frequently Asked Questions

What should you know about 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.

What should you know about syntax using annotation?

There are two syntaxes that can help create comments in SQL statements:

What should you know about as an 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:

Was this article helpful?

Your feedback helps us improve.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.