连接到另一个 SQL Server 的 T-SQL 语法是什么? [英] What is the T-SQL syntax to connect to another SQL Server?

查看:32
本文介绍了连接到另一个 SQL Server 的 T-SQL 语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我需要将存储过程 (SP) 从一个 SQL Server 复制到另一个 SQL Server,我可以在 SSMS 中右键单击该 SP,然后选择脚本存储过程为">创建到">新建查询编辑器窗口".然后,我通过右键单击该窗口并选择连接 > 更改连接...,然后选择新服务器和 F5 以在新服务器上运行创建来更改连接.

If I need to copy a stored procedure (SP) from one SQL Server to another I right click on the SP in SSMS and select Script Stored Procedure as > CREATE to > New Query Editor Window. I then change the connection by right clicking on that window and selecting Connection > Change Connection... and then selecting the new server and F5 to run the create on the new server.

所以我的问题是连接到另一个 SQL Server 的 T-SQL 语法是什么?"这样我就可以将它粘贴到创建脚本的顶部并按 F5 来运行它,它会切换到新服务器并运行创建脚本.

So my question is "What is the T-SQL syntax to connect to another SQL Server?" so that I can just paste that in the top of the create script and F5 to run it and it would switch to the new server and run the create script.

在输入问题时,我意识到如果我向您提供我正在尝试做的事情的背景,那么您可能会想出一个更快更好的方法来完成此任务.

While typing the question I realized that if I gave you the back ground to what I'm trying to do that you might come up with a faster and better way from me to accomplish this.

推荐答案

此外,请确保在编写涉及链接服务器的查询时,包含如下方括号:

Also, make sure when you write the query involving the linked server, you include brackets like this:

SELECT * FROM [LinkedServer].[RemoteDatabase].[User].[Table]

我发现至少在 2000/2005 年,[] 括号是必要的,至少在服务器名称周围.

I've found that at least on 2000/2005 the [] brackets are necessary, at least around the server name.

这篇关于连接到另一个 SQL Server 的 T-SQL 语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆