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.
Then hold down Alt + F1. This is what you will see.
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.
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.
Then hold down Alt + F1 again. You will see the same result.
Keyboard shortcut Ctrl + F1 – retrieve procedure code
Last tip is to use Ctrl + F1 to retrieve procedure code. Give it a try!