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

👁️ 8056 ❤️ 852
斜杠星型(块注释)(Transact-SQL) - SQL Server

适用于:SQL ServerAzure SQL 数据库Azure SQL 托管实例Azure Synapse Analytics分析平台系统(PDW)Microsoft Fabric 中的 SQL 分析终结点Microsoft Fabric 中的仓库Microsoft Fabric 中的 SQL 数据库

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

Transact-SQL 语法约定

Syntax

/*

text_of_comment

*/

Arguments

text_of_comment

是注释的文本。 它是一个或多个字符串。

Remarks

注释可以插入单独行中,也可以插入 Transact-SQL 语句中。 多行的注释必须用 /* 和 */ 指明。 用于多行注释的样式规则是,第一行用 /* 开始,接下来的注释行用 ** 开始,并且用 */ 结束注释。

注释没有最大长度限制。

支持嵌套注释。 如果在现有注释内的任意位置上出现 /* 字符模式,便会将其视为嵌套注释的开始,因此,需要使用注释的结尾标记 */。 如果没有注释的结尾标记,便会生成错误。

例如,以下代码生成一个错误。

DECLARE @comment AS VARCHAR(20);

GO

/*

SELECT @comment = '/*';

*/

SELECT @@VERSION;

GO

若要解决该错误,请执行以下更改。

DECLARE @comment AS VARCHAR(20);

GO

/*

SELECT @comment = '/*';

*/ */

SELECT @@VERSION;

GO

Examples

以下示例使用注释解释将要执行哪个代码段。

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)

← 古巴比伦 黄日华最新代言价格—黄日华代言费多少? →