斜線星形 (區塊註解) (Transact-SQL)

適用于: Microsoft Fabric 中 Microsoft Fabric 倉儲中的 SQL Server Azure SQL 資料庫 Azure SQL 受控執行個體 Azure Synapse Analytics Analytics Platform System (PDW) SQL 分析端點

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

Transact-SQL 語法慣例

Syntax

/*  
text_of_comment  
*/  

注意

若要檢視 SQL Server 2014 (12.x) 和舊版的 Transact-SQL 語法,請參閱 舊版檔

引數

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 AdventureWorks2022;  
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 AdventureWorks2022 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  

另請參閱

-- (註解) (Transact-SQL)
流程控制語言 (Transact-SQL)