/*...*/ (註解) (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 AdventureWorks2012;
GO
/*
This section of the code joins the Person table with the Address table,
by using the Employee and BusinessEntityAddress tables in the middle to
get a list of all the employees in the AdventureWorks2012 database
and their contact information.
*/
SELECT p.FirstName, p.LastName, a.AddressLine1, a.AddressLine2, a.City, a.PostalCode
FROM Person.Person AS p
JOIN HumanResources.Employee AS e ON p.BusinessEntityID = e.BusinessEntityID
JOIN Person.BusinessEntityAddress AS ea ON e.BusinessEntityID = ea.BusinessEntityID
JOIN Person.Address AS a ON ea.AddressID = a.AddressID;
GO