Home > SQL Challenge > SQL #48 – Block selection with keyboard shortcut in SQL Management Studio (SSMS)

SQL #48 – Block selection with keyboard shortcut in SQL Management Studio (SSMS)

In a previous blog, SQL #47 – Too many in-line comments totally destroy code readability, I made a point that all SQL developers need to have a consistent writing style to achieve high level of code readability.

Being productive in SQL Management Studio will be your first step to achieve this goal.

In this blog, I’ll show you one trick I use every day in SQL Management Studio. This is one of the many keyboard shortcuts I use to be productive and to achieve the goal of high level of code readability.

I use a lot of tabs/indents in every query I wrote. Hitting the Tab key twenty times for twenty columns can be very tiring (and boring).

Goal

Let’s say you want to type a simple SELECT statement with a style as the following. There are two tab spaces after each comma. 

image 

You can certainly insert the comma and two Tab spaces for each column, on each line.

I’ll show you a more fun way to do that, and a more productive way.

Block Selection with Keyboard Shortcut Alt + Shift

Yes, block selection is more fun.

Start to insert the comma, and two Tab spaces for the first three lines.

image

Put your cursor to the beginning line for YearID, before the comma. Then hold down Alt + Shift, and move the right and down arrow key until you have a block selection as shown below

image

Block Copy with Keyboard Shortcut Ctrl + C

Let go of the Alt and the Shift key, the block selection will remain. Then press Ctrl + C to copy the block selection.

Now you are ready to insert the block selection anywhere you want.

Block Insert with Keyboard Shortcut Ctrl + V

The keyboard shortcut pair Ctrl + C and Ctrl + V is the only thing I can remember from my early days of programming in C.

Now point your cursor to before column QuarterNumber and press Ctrl + V. You will witness the magic.

Practice the above three Keyboard Shortcuts a couple of times

You are going to a pro!

Have fun!

  1. DEREK
    June 26, 2011 at 7:57 am

    Interesting. Very good to know.

    Like

  1. June 26, 2011 at 1:21 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: