/*...*/ (Comment)

Transact-SQL Reference

Transact-SQL Reference

/*...*/ (Comment)

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

Syntax

/ * text_of_comment * /

Arguments

text_of_comment

Is the character string(s) containing the text of the comment.

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.

Note  Including a GO command within a comment generates an error message.

Examples

This example uses comments to document and test the behavior during different phases of development for a trigger. In this example, parts of the trigger are commented out to narrow down problems and test only one of the conditions. Both styles of comments are used; SQL-92 style (--) comments are shown both alone and nested.

Note  The following CREATE TRIGGER statement fails because a trigger named employee_insupd already exists in the pubs database.

CREATE TRIGGER employee_insupd
/*
   Because CHECK constraints can only reference the column(s)
   on which the column- or table-level constraint has 
   been defined, any cross-table constraints (in this case, 
   business rules) need to be defined as triggers.

   Employee job_lvls (on which salaries are based) should be within 
   the range defined for their job. To get the appropriate range, 
   the jobs table needs to be referenced. This trigger will be 
   invoked for INSERT and UPDATES only. 
*/
ON employee
FOR INSERT, UPDATE
AS
/* Get the range of level for this job type from the jobs table. */
DECLARE @min_lvl tinyint,      -- Minimum level var. declaration
   @max_lvl tinyint,         -- Maximum level var. declaration
   @emp_lvl tinyint,         -- Employee level var. declaration
   @job_id smallint            -- Job ID var. declaration
SELECT @min_lvl = min_lvl,      -- Set the minimum level
   @max_lvl = max_lvl,          -- Set the maximum level
   @emp_lvl = i.job_lvl,      -- Set the proposed employee level
   @job_id = i.job_id         -- Set the Job ID for comparison
FROM employee e, jobs j, inserted i 
WHERE e.emp_id = i.emp_id AND i.job_id = j.job_id
IF (@job_id = 1) and (@emp_lvl <> 10) 
BEGIN
   RAISERROR ('Job id 1 expects the default level of 10.', 16, 1)
   ROLLBACK TRANSACTION
END
/* Only want to test first condition. Remaining ELSE is commented out.
-- Comments within this section are unaffected by this commenting style.
ELSE
IF NOT (@emp_lvl BETWEEN @min_lvl AND @max_lvl) -- Check valid range
BEGIN
   RAISERROR ('The level for job_id:%d should be between %d and %d.',
      16, 1, @job_id, @min_lvl, @max_lvl)
   ROLLBACK TRANSACTION
END
*/
GO

See Also

-- (Comment)

Control-of-Flow Language

Using Comments