| title | Slash Star Comment (Transact-SQL) | Microsoft Docs | ||||
|---|---|---|---|---|---|
| ms.custom | |||||
| ms.date | 07/27/2017 | ||||
| ms.prod | sql-non-specified | ||||
| ms.reviewer | |||||
| ms.suite | |||||
| ms.technology |
|
||||
| ms.tgt_pltfrm | |||||
| ms.topic | language-reference | ||||
| f1_keywords |
|
||||
| dev_langs |
|
||||
| helpviewer_keywords |
|
||||
| ms.assetid | 4d9ab1b2-4bbb-4c16-beb1-cafc1af7417c | ||||
| caps.latest.revision | 30 | ||||
| author | BYHAM | ||||
| ms.author | rickbyh | ||||
| manager | jhubbard |
[!INCLUDEtsql-appliesto-ss2008-asdb-xxxx-xxx_md]
Indicates user-provided text. The text between the /* and */ is not evaluated by the server.
Transact-SQL Syntax Conventions
/*
text_of_comment
*/
text_of_comment
Is the text of the comment. This is one or more character strings.
Comments can be inserted on a separate line or within a [!INCLUDEtsql] statement. Multiple-line comments must be indicated by /* and */. A stylistic convention often used for multiple-line comments is to begin the first line with /*, subsequent lines with **, and end with */.
There is no maximum length for comments.
Nested comments are supported. If the /* character pattern occurs anywhere within an existing comment, it is treated as the start of a nested comment and, therefore, requires a closing */ comment mark. If the closing comment mark does not exist, an error is generated.
For example, the following code generates an error.
DECLARE @comment AS varchar(20);
GO
/*
SELECT @comment = '/*';
*/
SELECT @@VERSION;
GO
To work around this error, make the following change.
DECLARE @comment AS varchar(20);
GO
/*
SELECT @comment = '/*';
*/ */
SELECT @@VERSION;
GO
The following example uses comments to explain what the section of the code is supposed to do.
USE AdventureWorks2012;
GO
/*
This section of the code joins the Person table with the Address table,
by using the Employee and BusinessEntityAddress tables in the middle to
get a list of all the employees in the AdventureWorks2012 database
and their contact information.
*/
SELECT p.FirstName, p.LastName, a.AddressLine1, a.AddressLine2, a.City, a.PostalCode
FROM Person.Person AS p
JOIN HumanResources.Employee AS e ON p.BusinessEntityID = e.BusinessEntityID
JOIN Person.BusinessEntityAddress AS ea ON e.BusinessEntityID = ea.BusinessEntityID
JOIN Person.Address AS a ON ea.AddressID = a.AddressID;
GO
-- (Comment) (Transact-SQL)
Control-of-Flow Language (Transact-SQL)