スラッシュ アスタリスク (ブロック コメント) (Transact-SQL)

適用対象:SQL ServerAzure SQL DatabaseAzure SQL Managed InstanceAzure Synapse AnalyticsAnalytics Platform System (PDW)Microsoft Fabric の SQL 分析エンドポイントMicrosoft Fabric のウェアハウス

ユーザーが入力したテキストを示します。 /**/ の間のテキストは、サーバーによって評価されません。

Transact-SQL 構文表記規則

構文

/*  
text_of_comment  
*/  

Note

SQL Server 2014 (12.x) 以前のバージョンの Transact-SQL 構文を確認するには、以前のバージョンのドキュメントを参照してください。

引数

text_of_comment
コメントのテキストです。 1 つ以上の文字列です。

解説

コメントは、単独行に指定したり、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)