Tip for SQL Server Management Studio

You know the feeling when you discover a feature in software that you use daily for many years, and could have made your work so much simpler had you known about it earlier? I recently discovered such a feature in Microsoft SQL Server Management Studio (SSMS). Michael Zilberstein—a member of the Israeli SQL Server User Group—delivered a presentation on statistics in Microsoft SQL Server. At some point I notice that he highlights a piece of code that is commented out, without the comments, and runs the code. I was pleasantly surprised to know that this was possible, since I remembered all the times that I had to uncomment before I could run a piece of code that was commented out, or when I just wanted to copy that code without the comments. So, the trick is to simply press the Alt button, and then highlight the rectangle you like. Here’s a screenshot that demonstrates a highlighted rectangle of code:

Now you can either run or copy the highlighted code.

I figured that if I’ve been working for years with SSMS and haven’t known about this features, many other programmers probably don’t know about it as well and will find it useful.

Cheers,

BG

Discuss this Article 2

saeid hasani
on Nov 15, 2012
Very useful trick. Regards, Saeid
pjmssb
on Mar 10, 2008
How about /* --*/ You only needs to add "--" to "/*" in order to convert it in a comment and all the SQL code between "--/*" and "--*/" will be "runable". When "" is composed of many lines of code this may be convenient, when are few code lines or there are many other pieces of code I would like better to highlight the code. Regards, Pablo

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.