Languages
[Edit]
EN

MS SQL Server - Comments

0 points
Created by:
Huzaifa-Ball
385

In this article, we would like to show you how to use comments in MS SQL Server.

Quick solution:

-- Single-line comment
/* 
  Multi-line
  comment
*/

Practical examples

Example 1

In this example, we use a single-line comment as a code fragment explanation:

-- Select all users
SELECT * FROM [users];

Example 2

In this we use a single-line comment to ignore a statement at the end of the line:

SELECT * FROM [users] -- WHERE [name]='Tom';

Example 3

In this example we use a multi-line comment as a code fragment explanation:

/* Select all
 from the [users] table: */
SELECT * FROM [users];

Example 4

In this example, we use a multi-line comment to ignore many statements:

/*SELECT * FROM [users];
SELECT * FROM [products];
SELECT * FROM [orders];*/
SELECT * FROM [departments];

Example 5

In this example, we use a multi-line comment to ignore part of a line:

SELECT [name], /*[surname]*/ [country] FROM [users];

MS SQL Server

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join