突出重围:Transact-SQL管理与开发实例精粹
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人

1.4 注释

Transact-SQL代码中,添加注释信息是一个很好的习惯,便于程序的可读性。

1.4.1 添加单行注释信息

如果需要添加单行的注释信息,可以使用双连字符(--),比如下面的代码。

        USE AdventureWorks;
        GO
        -- Single line comment.

        SELECT EmployeeID, Title
        FROM HumanResources.Employee;
        GO

1.4.2 添加多行注释信息

如果需要添加多行的注释信息,可以使用正斜杠星号字符对(/**/),比如下面的代码。

        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