Comments in SQL Server Transact-SQL Statements


How to enter comments in SQL Server Transact-SQL statements?



There are 2 ways to enter comments within Transact-SQL statements:

  • Starting comments with two dashes "--": Everything between "--" and the end of the line is treated as a comment.
  • Entering comments between "/*" and "*/": Everything between "/*" and "*/" is treated as a comment.

Here are some good examples on how to enter comments:

/* The following statement
   creates a table 
   called fyi_links */ 
CREATE TABLE fyi_links (
   id INTEGER PRIMARY KEY,   -- the primary key
   url VARCHAR(80) NOT NULL, -- address of the link
   notes VARCHAR(1024),
   counts INT,               -- number of clicks
   created DATETIME NOT NULL DEFAULT(getdate())

-- Get rid of this table
DROP TABLE fyi_links;

By the way, comments are not considered as statements.


Statement Batch in SQL Server Transact-SQL

Start and End of Statement in SQL Server Transact-SQL

General Questions on Microsoft SQL Server Transact-SQL

⇑⇑ SQL Server Transact-SQL Tutorials

2017-05-29, 1732🔥, 0💬