Session management (7 minutes)

Keep your hands on the keyboard

This video covers managing new sessions with CTRL + N, CTRL + U, and CTRL + E

I am obsessed with CTRL + TAB

Switching between sessions with CTRL + TAB starts at 4:40.

What if CTRL + U doesn’t work?

If CTRL + U doesn’t work for you, it might be this bug. Updating SSMS to the latest build should fix it for most people. If it still doesn’t work for you, check if you have any third party add-ins which could be causing an issue: I know of one case where that interfered.

Transcript

One of the most frequent and useful things that we do is we manage sessions and queries in Management Studio. So we’re going to start out there.

We are beginning our demo in the master database

I’m already in the master database, but just in case your session automatically connects somewhere else, we say ‘use master’ at the beginning of the session.

Now, one really common problem is I just want to stick to the keyboard more often. I’m tired of reaching for the mouse. And so, getting some favorite shortcuts that you can use for common tasks like opening a new session window, is really useful.

My favorite common shortcuts

My favorites are:

  • control + n for opening a new session
  • control + u for getting up to that use database control
  • control + e for executing a query, and then finally
  • control + r for hiding and showing the results pane for a query

A quick demo

What I’m going to do is I’m going to copy out this query. I’m copying it to my clipboard with control + c.

And now I want to run it in a different session. If I want to do that, I’m going to say control + n to open a new session window which automatically attempts to connect to the same instance where I was connected before.

For safety reasons, I can always verify: am I really connected where I want to be connected? Look at the bottom right and indeed, this time I am.

I’m going to paste – control + v – that query into the window. Now I’ve got the red Intellisense highlight saying I don’t recognize this stuff. That’s because I’m not in the right database context.

Control + u

Control + u takes me up into that database dialog there, and it makes the database name highlighted in blue. I took my hands off the keyboard because I’m demoing, but I don’t have to. Just control + u gets me up there and I can start typing the database name that I want to be in.

I just typed capital W and it auto completes WideWorldImporters for me. If I hit return to make it accept that, it immediately returns my cursor to the window where I started.

Control + e

I can – if I’m ready to execute the query – go ahead and execute with control + e.

Control + r

If I’ve got a big script here, I might not want to look at those results too long. I might say okay, I see some stuff there, but I want to look now at my whole script again.

Control + r takes that results pane away, and now I can see my session window again and type in it.

If I want them back at any time, control + r will toggle it back.

Closing sessions using alt (the “I don’t remember the shortcut” button)

Let’s say I’m done in this session window, and I think there’s some sort of shortcut key to close it.

For closing windows, the way I actually like to do it is to use the alt button and to go up to the file menu.

Now I already hit alt and as soon as you do, notice that file is highlighted in yellow up here. I can now arrow around among that menu or any of the underlined letters. If I want to get to the query menu, I can just type q and it’ll take me over to query and I find that so useful because we can’t memorize everything.

I like knowing a lot of commands by heart, but this alt thing, I just did it again to get back up there. It’s so useful.

So I’m going to hit f, which selects that file menu, and now if I hit c, it’s going to find close, since the c is underlined and say do you want to save anything in this section? I right arrow key over to the no, hit enter, and that session is gone. That’s super duper useful.

Recap: Control + n for new session, control + u for use database, control + e for execute query, and control + r for hiding and showing that results window.

One last shortcut for managing sessions— and this is one of my favorites.

Control + tab for switching between open sessions

We can easily navigate between our open sessions in Management Studio by using control + tab.

Right now, I am connected to session O1, about open sessions. I want to quickly see hey, what else do I have open?

I hold down control and then hit tab and this brings up a little management window.

Now notice that the session it highlighted isn’t the one I had open now. If I just take my fingers off, it switches to me to whatever was next in the list, which currently is the O2 script. But let’s say I wanted to go to a different one. I can control + tab and navigate through that list and it even shows me more of the file name at the bottom of the window. Let’s say I want to go back to O1, I can go back there.

Alt + F7 to switch to other tool windows

We can even use alt + F7 on the left side of that screen. I’m holding down alt, and now I’m hitting F7 to navigate to other tool windows.

Let’s say I want to get to Object Explorer without using the mouse. I can do it that way and then I can arrow around in Object Explorer. If I want to get back over to a session window, control + tab brings me up, back into the file list on the right side.

Now what do I actually use?

I have a hard time remembering alt + F7, and it just doesn’t come that naturally to me. But I do find control + tab to be really, really natural. And I think that one is really cool and fun to easily switch between open sessions in Management Studio.