Comments

Last modified on April 25th, 2020 by DigitalIndiaInfo Team.


Comments in Sql Server

Line comments start with two dashes

Line comments start with two dashes(–) and ends with carriage returns. Everything between two dashes (–) and carriage returns is considered as comment. This comment can be placed anywhere in the code. This comment can be placed after code in the same line and everything before two dashes (–) will execute like normal T-SQL and after two dashes (–) will not be executed and considered as comment.

Example:

                    SELECT *
                    FROM Sales.Products --This table name
                    WHERE ProductID > 10 --This is a filter condition
                 

2) Block comments

Block comments start with a forward-slash and asterisk (/*) and ends with an asterisk and forward-slash (*/). Everything between forward-slash and asterisk (/*) and ends with an asterisk and forward-slash (*/) is considered as comments. This comment is usually placed before or after a big chunk of code, however it can be placed anywhere in the code. This comment can span more than one line.

                    /*This is an example of blog comment
                    Following table is an example of same retrieve
                    and filter condition*/
                    SELECT *
                    FROM Sales.Products
                    WHERE ProductID > 10
                

Additional Notes:
There is no limit for the length of the comment.
Comments can be nested.
GO Command is not allowed anywhere in commenting text.



References :

  • www.tutorial.digitalindiainfo.com