Comments are nonexecuting text strings in program code (also known as remarks). Comments can be used to document code or temporarily disable parts of Transact-SQL statements and batches being diagnosed. Using comments to document code makes future program code maintenance easier. Comments are often used to record the program name, the author name, and the dates of major code changes. Comments can be used to describe complicated calculations or explain a programming method.
Microsoft® SQL Server™ supports two types of commenting characters:
Multiple-line /* */ comments cannot span a batch. The complete comment must be contained within a batch. For example, in SQL Server Query Analyzer and the osql utility, the GO command signals the end of a batch. When the utilities read the characters GO in the first two bytes of a line, they send all the code since the last GO command to the server as one batch. If a GO occurs at the start of a line between the /* and */ delimiters, then an unmatched comment delimiter will be sent with each batch and they will trigger syntax errors. For example, the following script contains syntax errors:
USE Northwind
GO
SELECT * FROM Employees
/* The
GO in this comment causes it to be broken in half */
SELECT * FROM Products
GO
Here are some valid comments:
USE Northwind
GO
-- First line of a multiple-line comment.
-- Second line of a multiple-line comment.
SELECT * FROM Employees
GO
/* First line of a multiple-line comment.
Second line of a multipl-line comment. */
SELECT * FROM Products
GO
-- Using a comment in a Transact-SQL statement
-- during diagnosis.
SELECT EmployeeID, /* FirstName, */ LastName
FROM Employees
-- Using a comment after the code on a line.
USE Northwind
GO
UPDATE Products
SET UnitPrice = UnitPrice * .9 -- Try to build market share.
GO
Here is some basic information regarding comments: