/*...*/ (コメント) (Transact-SQL)

ユーザーの入力したテキストを示します。サーバーが、/* と */ で囲まれたテキストを評価することはありません。

トピック リンク アイコンTransact-SQL 構文表記規則

構文

/*
text_of_comment
*/

引数

  • 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 AdventureWorks2008R2;
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 AdventureWorks2008R2 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