表示用戶提供的文本。服務(wù)器不對(duì)位于 /* 和 */ 注釋字符之間的文本進(jìn)行評(píng)估。
/ * text_of_comment * /
text_of_comment
包含注釋文本的字符串。
注釋可以插入單獨(dú)行中,或者 Transact-SQL 語(yǔ)句中。多行的注釋必須用 /* 和 */ 指明。用于多行注釋的樣式規(guī)則是,第一行用 /* 開(kāi)始,接下來(lái)的注釋行用 ** 開(kāi)始,并且用 */ 結(jié)束注釋。
注釋沒(méi)有最大長(zhǎng)度限制。
說(shuō)明 在注釋中包含 GO 命令會(huì)生成一個(gè)錯(cuò)誤信息。
下面的示例使用注釋來(lái)注明和測(cè)試在開(kāi)發(fā)觸發(fā)器的不同階段期間的行為。在下面的示例中,將部分的觸發(fā)器標(biāo)為注釋語(yǔ)句是為了縮小問(wèn)題范圍,并且只測(cè)試其中一個(gè)條件。使用了兩種注釋語(yǔ)句樣式,SQL-92 樣式的注釋 (--) 分別以單獨(dú)和嵌套的方式顯示。
說(shuō)明 下面 CREATE TRIGGER 語(yǔ)句失敗的原因是命名為 employee_insupd 的觸發(fā)器已經(jīng)存在于 pubs 數(shù)據(jù)庫(kù)中。
相關(guān)文章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