Comments in T-SQL SQL Server 2008 2012 with examples
Examples of Comments in T-SQL SQL Server 2008 2012
- In this article i will explain the types of comments in SQL Server Programming in SQL Server 20012 or 2008
- Basically there are two types of commenting syntax that are widely used in SQL Programming which are described as follows
- Block Comments
- In-Line Comments
let us now see each comment pattern with examples
Block Comments
Block Comments
- Block comments are typically used at the beginning of a T-SQL code to provide an explanation about the purpose of the code.
- The following example contains a block comment that describes the purpose of the T-SQL code. Comments are enclosed within the /* and */ elements.
/* The purpose of the Transact-SQL
statement below is to retrieve the
Firstname and Lastname of StudentID 1 */
USE Adventureworks
GO
SELECT Firstname, Lastname
FROM students
WHERE StudentID = 1
In-Line Comments
- In-line comments are added within the T-SQL code to add descriptive comments to portions of the code.
- In-line comments begin with -- (two hyphens). Any characters to the right of this are commented out on the line where the -- are placed, and are excluded from the T-SQL statement. Comments inserted with -- are terminated by the newline character.
- Additional elements can also be used to add flexibility and logic to any T-SQL statements. These elements can add dynamic capabilities to your statements and logic, and provide you with the ability to create powerful T-SQL statements
- The following is an example of an in-line comment within a T-SQL statement.
Example:
USE Adventureworks
GO
SELECT Firstname, Lastname
FROM students
WHERE StudentID = 1 -- Only StudentID one is returned
0 comments:
Post a Comment