您的位置:首页 > 数据库

sql server 2005 T-SQL /*...*/(注释)(Transact-SQL)

2007-12-20 13:24 501 查看
表示用户提供的文本。服务器不计位于 /**/ 之间的文本。


Transact-SQL 语法约定


语法

/*
text_of_comment
*/



参数

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 AdventureWorks;
GO
/*
This section of the code joins the
Contact table with the Address table, by using the Employee table in the middle
to get a list of all the employees in the AdventureWorks database and their
contact information.
*/
SELECT c.FirstName, c.LastName, a.AddressLine1, a.AddressLine2, a.City
FROM Person.Contact c
JOIN HumanResources.Employee e ON c.ContactID = e.ContactID
JOIN HumanResources.EmployeeAddress ea ON e.EmployeeID = ea.EmployeeID
JOIN Person.Address a ON ea.AddressID = a.AddressID;
GO
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: