THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

John Paul Cook

Using Alt-select in SSMS, Word, and elsewhere

A surprising number of database people and Windows users in general don’t know about Alt select. This is a Windows technique not unique to SSMS that allows a user to select an arbitrary rectangular region of text and delete it, cut it, or copy it.

Where I find Alt select particularly useful in SSMS is when I have a bunch of inline comments that are too far to the right. I want to delete much of the whitespace in front of them to move them to the left without disturbing any of the rest of the T-SQL.

In the screen capture below, you can see that a rectangular region is highlighted in light blue. I selected this rectangular region with the mouse. It can be removed by hitting the delete key, pressing Ctrl+X, or right-clicking and selecting Cut.

Before selecting the text with the mouse, hold down the Alt key. I recommend not touching the mouse at all before holding down the Alt key. After holding down the Alt key, place the mouse cursor at any of the corners of the rectangle and move the mouse to select your desired rectangular region. You can even paste the rectangular region of text that you obtained with this technique.


The Alt select technique also works in Word, but not Notepad.

Published Saturday, September 8, 2012 10:12 AM by John Paul Cook

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



Chris Nelson said:

It may not work in Notepad, but it works in Notepad++ and many other programming editors. I believe it also works in Adobe Acrobat, which makes it useful for monthly budgeting.

September 9, 2012 8:11 AM

dbaInTraining said:

Thanks for the tip.  This will prove helpful.

September 17, 2012 3:14 PM

Jared Ko said:

Also useful for execution of commented-out code. Usually you'll have some sort of indenting in place such as:

  SELECT DepartmentID

       , Name

       , GroupName

       , ModifiedDate

  FROM HumanResources.Department

-- WHERE ModifiedDate > '2012/09/17'

Execute it as a batch and it won't execute the WHERE clause. Hold down ALT and highlight all of the text (including the WHERE clause) and you'll get a subset.

I also use it in comment blocks:

-- Sample Execution:

-- SELECT TOP 1000

-- FROM HumanResources.Department


Use ALT to highlight just the query after the dashes and execute...

September 18, 2012 7:52 PM

drsql said:

When I learned about this around the time of my 2008 book, it saved me many many painful formatting casts to make text results look good by just hacking out whitespace like you have described.

You can also paste in a column of text before or after code as well, which is where it becomes even more amazing. So if you have:








You can alt select and copy the 123, and then paste after the 1 and end up with




Amazingly useful.

February 5, 2013 5:02 PM

Valerie said:

I have been using this for years, but it doesn't seem to work anymore - when I hold down the Alt key I get this annoying "Research" panel. Even if I mouse-down first and then hold the Alt key, it just selects horizontally.  Clues?

June 7, 2013 3:44 PM

Leave a Comment


About John Paul Cook

John Paul Cook is a database and Azure specialist in Houston. He previously worked as a Data Platform Solution Architect in Microsoft's Houston office. Prior to joining Microsoft, he was a SQL Server MVP. He is experienced in SQL Server and Oracle database application design, development, and implementation. He has spoken at many conferences including Microsoft TechEd and the SQL PASS Summit. He has worked in oil and gas, financial, manufacturing, and healthcare industries. John is also a Registered Nurse currently studying to be a psychiatric nurse practitioner. Contributing author to SQL Server MVP Deep Dives and SQL Server MVP Deep Dives Volume 2. Connect on LinkedIn

This Blog



Privacy Statement