-->

“Favorites” or “macros” in SQL Server Management s

2020-07-07 06:16发布

问题:

I have a few databases that I always use SQL Server Management Studio with. I'd like to be able to create a toolbar button or keyboard shortcut that automatically opens a new query window (in the current SSMS instance) and connects to a given (registered, perhaps) database. That's it. That's all I need. And this ashtray, and the paddle game, and the remote control. That's all I need.

As it is now, I have to expand the Object Explorer, collapse/expand two to eight trees, right-click on my database, and choose "New Query". I see no way to do it, this would probably save me 30-60 seconds a day.

回答1:

I am developer of SSMSBoost add-in and it has exactly what you need: is allows to manage the list of preferred servers/databases and quickly switch between them via custom Combobox on the toolbar, you can also say, if you want all servers to be opened in ObjectExplorer upon start-up and if a new query window should be opened for them (per-server setting).

SSMSBoost also allows you to define aliases (instead of server8273128 > MainServer, server231232> BackupServer etc..) It has more features - but they are out of scope of this topic.

Look at the picture - you can see Quick Connection Switch combobox with some Servers from preferred connections, "SSMSBoostDemoServer" - is an alias for the server, next name - is original.

One more thing - add-in is available in free edition.



回答2:

Have you tried creating a registered server?

Take a look at the "Registered Servers" view (Ctrl-Alt-G). Define a server connection. Set the password, and click the "Remember Password" checkbox if you're not using Windows Authentication. On the "Connection Properties" tab, set your preferred database. Save the server registration.

Now, to connect to that database on that server (assuming you've got the Registered Server pane always visible, as I do), you just need to select that registration node and hit Ctrl-N.

That should save you at least 43 seconds a day.



回答3:

I haven't read through the whole thing yet, but this article is about creating an add-in for SSMS, which you might be able to do in order to automate what you want.



回答4:

You could create a shortcut to launch SQL Server Management studio using command line parameters, as follows:

SQLWB.EXE - launches SQL Server Management Studio from the Command Prompt or Start -> Run text box. Through its switches, you can specify which type of server (-t S, -t A, or -t C for SQL Server, Analysis Server, or SQL Server Mobile Edition, respectively), server name (-S), and database (-d) you want to connect to, provide authentication information, or designate which queries, projects, or solutions to open (-i filename). The defaults (in absence of switches) are defined in the Tools -> Options menu of the SQL Server Management Studio.

[Source]



回答5:

This solution is admittedly a hack, but if you can figure out the exact keystrokes needed to accomplish each 'macro', you can use a free tool like AutoHotKey to automate the keystrokes using whatever shortcuts you wish.