Archive

Posts Tagged ‘SSMS’

SQL #49 – Retrieve table structure with keyboard shortcut in SQL Management Studio (SSMS)

June 26, 2011 Leave a comment

Many readers like my previous tip of SQL #48 – Block selection with keyboard shortcut in SQL Management Studio (SSMS). So in this blog post, I’ll show you another keyboard shortcut I use in SSMS. This one will increase your productivity in SSMS, and of cause also fun to use.

Scenario 1

You are reading some SQL code developed by other developers. The procedure code reads from a dozen SQL tables (or views), and writes to a couple of other tables. You are new to the code, and have tight schedule to modify the code for the new requirements from business.

Scenario 2

If you are like me who follows a very consistent code writing style, you want to put each column on a separate line, but you don’t want to do your own typing.

Solution – use Alt + F1 to retrieve a table structure

For the above two scenarios, what you want to do is to list out all the columns in a table, and also all the constraints, identity field and indexes for the tables. 

First, double click the table to select it.

image

Then hold down Alt + F1. This is what you will see.

image

For the scenario 2, just simply copy all the column names to the query section.

By default, Alt + F1 is equivalent to sp_help. If you have not changed this default setting, you are good to go.

image

Workaround for tables in schema other than dbo – add square bracket [ ]

If you follow SQL Server’s recommendation of creating schemas for your tables (for security, or for best practice, or whatever reason), the above keyboard shortcut will not work.

I create schemas in my design. I don’t like the workaround, but I have no choice.

First, add square bracket [ ] to the beginning and the end of the table name (incl. the schema name), then  double click the table to select it.

image 

Then hold down Alt + F1 again. You will see the same result.

image

Keyboard shortcut Ctrl + F1 – retrieve procedure code

Last tip is to use Ctrl + F1 to retrieve procedure code. Give it a try!

Categories: SQL Challenge Tags: ,

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

June 18, 2011 2 comments

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!

Follow

Get every new post delivered to your Inbox.

Join 26 other followers