斜杠星型(块注释)(Transact-SQL)

适用于:SQL ServerAzure SQL 数据库Azure SQL 托管实例Azure Synapse AnalyticsAnalytics Platform System (PDW)Microsoft Fabric 中的 SQL 分析终结点Microsoft Fabric 中的仓库

表示用户提供的文本。 服务器不计位于 /**/ 之间的文本。

Transact-SQL 语法约定

语法

/*  
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)