Udostępnij za pośrednictwem


/*...*/ (Comment) (Transact-SQL)

Indicates user-provided text. The text between the /* and */ is not evaluated by the server.

Topic link iconTransact-SQL Syntax Conventions

Syntax

/*
text_of_comment
*/

Arguments

  • text_of_comment
    Is the text of the comment. This is one or more character strings.

Remarks

Comments can be inserted on a separate line or within a Transact-SQL 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 

Examples

The following example uses comments to explain what the section of the code is supposed to do.

USE AdventureWorks;
GO
/*
This section of the code joins the 
Contact table with the Address table, by using the Employee table in the middle 
to get a list of all the employees in the AdventureWorks database and their 
contact information.
*/
SELECT c.FirstName, c.LastName, a.AddressLine1, a.AddressLine2, a.City
FROM Person.Contact c 
JOIN HumanResources.Employee e ON c.ContactID = e.ContactID 
JOIN HumanResources.EmployeeAddress ea ON e.EmployeeID = ea.EmployeeID
JOIN Person.Address a ON ea.AddressID = a.AddressID;
GO

See Also

Reference

-- (Comment) (Transact-SQL)
Control-of-Flow Language (Transact-SQL)

Other Resources

Comments

Help and Information

Getting SQL Server 2005 Assistance