Transact-SQL 参考

/*...*/(注释)

表示用户提供的文本。服务器不对位于 /**/ 注释字符之间的文本进行评估。

语法

/ * text_of_comment * /

参数

text_of_comment

包含注释文本的字符串。

注释

注释可以插入单独行中,或者 Transact-SQL 语句中。多行的注释必须用 /**/ 指明。用于多行注释的样式规则是,第一行用 /* 开始,接下来的注释行用 ** 开始,并且用 */ 结束注释。

注释没有最大长度限制。

说明  在注释中包含 GO 命令会生成一个错误信息。

示例

下面的示例使用注释来注明和测试在开发触发器的不同阶段期间的行为。在下面的示例中,将部分的触发器标为注释语句是为了缩小问题范围,并且只测试其中一个条件。使用了两种注释语句样式,SQL-92 样式的注释 (--) 分别以单独和嵌套的方式显示。

说明  下面 CREATE TRIGGER 语句失败的原因是命名为 employee_insupd 的触发器已经存在于 pubs 数据库中。

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

请参见

--(注释)

控制流语言

使用注释