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

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

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: ,
  1. avithohol
    June 4, 2014 at 3:23 pm

    very useful tips, thank you for the post

    Liked by 1 person

  1. No trackbacks yet.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: