Monday 6 January 2014

Pearls: SQL Comments

When you are writing SQL code, very often you run parts in isolation by commenting out what you don't need and uncommenting portion that is to be executed.
A very simple approach of writing SQL comments coupled with SSMS(studio) shortcuts for commenting/uncommenting sections of code can help you do your unit testing efficiently.
First you need to know these SSMS short cuts:
Cntrl+K followed by Cntrl+C :
This comments ​current SQL line
Cntrl+K followed by Cntrl+U:
This uncomments the current SQL line
​​
--/* booklist section starts
SELECT * FROM BookList
--*/
--/*Book section starts
SELECT * FROM Books
--*/​
​Now all you need to do to comment Booklist section is press cntrl+K &cntrl-U on line #1 . To uncomment back the section , you'll need to comment out the line#1 by pressing cntrl+K&cntrl+C

No comments:

Post a Comment