/*...*/ (註解) (Transact-SQL)

指出使用者提供的文字。伺服器不會評估 /**/ 之間的文字。

主題連結圖示Transact-SQL 語法慣例

語法

/*
text_of_comment
*/

引數

  • text_of_comment
    這是註解的文字。這是一或多個字元字串。

備註

註解可以插入個別行中,也可以插入 Transact-SQL 陳述式。多行註解必須用 /**/ 來表示。多行註解的常用樣式慣例是第一行開頭用 /*,後續的行用 **,結尾則是 */

註解沒有最大長度。

支援巢狀註解。如果現有註解內的任何位置出現 /* 字元模式,就會將它當作巢狀註解的開頭來處理,因此,需要一個結束的 */ 註解標示。如果結束的註解標示不存在,就會產生錯誤。

例如,下列程式碼會產生錯誤。

DECLARE @comment AS varchar(20);
GO
/*
SELECT @comment = '/*';
*/ 
SELECT @@VERSION;
GO 

若要暫時解決這個錯誤,請進行下列變更。

DECLARE @comment AS varchar(20);
GO
/*
SELECT @comment = '/*';
*/ */
SELECT @@VERSION;
GO 

範例

下列範例會利用註解來說明程式碼區段應該執行的動作。

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