In the past few weeks, I have had a chance to work more extensively with SSMS, creating stored procedures, views and mostly running ad-hoc queries to check and analyze the data. Over the course of time, I learned and set up a few shortcuts that helped me get things done faster, and in this post, I will try to summarize and list them.
1. Setting up query shortcuts
In addition, to the list of shortcuts supported by SSMS. SSMS also provides you an option to set up “query shortcuts”. In Tools > Options > Keyboard > Query Shortcuts you can configure Ctrl + N to run a part of a query.
In the example above, I have configured my Ctrl + 3 to execute “select top 10 * from ”. Now if I were to simply type in a table name and press Ctrl + 3, It would run the query with the table and return 10 rows of that table.
Another example I often use is saving complex queries and using IDs to execute them, saves a lot of my times writing those joins over and over again.
2. Changing the database name
This one is my favorite! I always people querying against the wrong database and then using their mouse and going through the list of available databases (and hoping that list is not longgg) and selecting the one they want to query against.
CTRL + ALT + J takes the control to the database selection panel, where you can type in the database name you want to select or simply use the up/down arrow to run through the list of available databases.
3. Show/Hide the result panel
CTRL + R can be used to toggle show/hide query result pane.
4. Upper Case / Lower Case
This shortcut is very useful when you are formatting your query, stored procedure, view and want some kind of standards with all the SQL keywords (INTO, VALUES, FROM etc) in use. I prefer to keep all my keywords capitalized and this shortcut helps me do that.
- CTRL + SHIFT +U — Converts the selected text to Upper Case
- CTRL + SHIFT +L — Converts the selected text to Lower Case
5. Comment and UnComment lines
You can comment and uncomment lines of code by using this combination shortcut keys.
- CTRL + K, CTRL + C — Comments selected lines of code
- CTRL + K, CTRL + U — UnComments selected lines of code
That’s all for now, I do plan to keep updating this list as and when I find more “un-common” useful shortcuts. Cheers!