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