Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

Shortcut: Change connection in SQL Server Management Studio

$
0
0

I commonly run into a few connection-related scenarios:

I'm working on a large query and need to run it against several servers, not concurrently, but one after the other. I've just made a database connection, and got my query ready, only to discover that I've connected to the wrong server.

Either way, what I've seen people do in these scenarios is to:

Select all the text in the current query Copy it Open a new query window Paste the code

That's all good but SQL Server Management Studio (SSMS) has had a simpler way of doing this for quite a while.

If you right-click in the middle of a query window, you can choose to change the connection. Here's an example. I opened a new query window and entered a query, only to find that it connected to the Azure server that I was working with earlier. The easiest option is to right-click and choose to change the connection:


Shortcut: Change connection in SQL Server Management Studio

After you click Change Connection , you can log on again:


Shortcut: Change connection in SQL Server Management Studio

And then I can continue in the same query window as before. This is particularly useful if I need to run some code against a test server, and once I've decided that it was correct, I can just change the connection and connect to the "real" server.

At the bottom-right of your query window, you can always see which server you are connected to:


Shortcut: Change connection in SQL Server Management Studio

And at the bottom-left, you can see your connection state:


Shortcut: Change connection in SQL Server Management Studio

Viewing all articles
Browse latest Browse all 3160

Latest Images

Trending Articles