Shortcut: Selecting and modifying rectangular regions in SSMS

I often see people using SQL Server Management Studio (SSMS) and doing very repetitive editing tasks that could easily be carried out by using the selection and changing of rectangular regions of code.

The simplest example of doing this is to insert a bit of text on a number of rows. Take the following code as an example:

I've got the skeleton of a list of columns in a CREATE TABLE statement but let's assume that I'm a "comma in front" person and want to put a few spaces and a comma, etc. in front of each column after the second. I could just put the cursor on the InvoiceID line and type what I wanted, then do the same again on the next line. I could do it on the first line, then select and copy it, and insert it into the front of every other line. But what I should do is put the cursor in front of InvoiceID, and while holding Alt-shift, use the down arrow to select the beginning of every line, then just type what I want.

Similarly, if I want to change text on a bunch of lines, I can do the same by using both down arrow and side arrow to select a rectangular region, then just type to replace. In this example, I have a table name that I want to change from InvoiceLines to OrderLines:

So I select the starting point, Alt-shift and arrows to select the rectangle, then just type:

If you weren't aware of this, I hope you find it useful.

 

 

2 thoughts on “Shortcut: Selecting and modifying rectangular regions in SSMS”

Leave a Reply

Your email address will not be published.