SQL Server: Two ways of "comment" ing script

Microsoft SQL Server has provision to comment script in two ways.

1) Single line comment:

Use two hyphens (--) for single-line comment. Comments inserted with -- are terminated by the newline character. There is no maximum length for comments. In SQL Server query editor comments will appear in green color.

Example:

-- This is a simple query
SELECT * FROM mytable
WHERE city = 'Bangalore' -- 101 Records

2) Multi line comment:

Use /* */. The text between the /* and */ is not compiled by the server. This will also appear in green color in SQL server editor window.

Example:

/*This is a simple Query
Created by Shiva
Created Date: 15-May-2010*/
SELECT * FROM mytable WHERE city = 'Bangalore'

No comments:

Post a Comment