This may seem like a trivial “trick”. I thought so too at first, but I’ve found that I use this trick over and over again.

When developing scripts, often times I find myself commenting some blocks of code out, either to explore, to test, to debug, or to simply try out other T-SQL constructs. When you have commented code using the C-style comment, it is easy to select any block of code inside and execute them:

/*
SELECT * FROM sometable;
GO
SELECT * FROM anothertable;
GO
*/

But what if you used SQL Server Management Studio’s (SSMS) single line comment shortcut to comment out parts of your code?

SSMS - Single Line Comment Shortcut

Of course you can use the uncomment shortcut, but that’s still a bit of work. Highlight code, move mouse to SSMS toolbar, click on icon, execute. No I’m not a whiner, I just like doing things more efficiently when possible. Imagine, take that one icon click, and if you do it 10x or 20x in a day, it adds up :)

What you can do (or try) is to press the ALT key, then highlight the code you want to execute, then execute.

Selecting and executing commented T-SQL code

Selecting and executing commented T-SQL code

Small trick that saves you one icon click. Seemingly trivial, but believe me, it does make your work faster.

VN:F [1.9.22_1171]
Rating: 3.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Selecting and Executing Commented T-SQL Code, 3.0 out of 10 based on 1 rating  
Be Sociable, Share!
  • Tweet