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).
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.
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.
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.
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!