连接到另一台服务器的 TSQL 命令 (SQL Server 2005)

TSQL command to connect to another server (SQL Server 2005)(连接到另一台服务器的 TSQL 命令 (SQL Server 2005))
本文介绍了连接到另一台服务器的 TSQL 命令 (SQL Server 2005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

是否有连接到另一台服务器的 TSQL 命令?

或者当您在查询窗口中时,连接到另一台服务器并显示查询窗口的键盘快捷键是什么?

我已经看到 Ctrl+N 在某些屏幕中弹出连接到服务器对话框,但是当我已经在查询窗口中并按 Ctrl+N 时,它只会打开另一个查询窗口.>

USE 命令可以让您连接到当前服务器上的其他数据库,但是否有一个命令可以让您连接到另一台服务器?

我使用的是 SQL Server 2005.

解决方案

您可以使用 OpenDataSource 带有链接服务器

OpenDataSource(provider_name, init_string)

例如

SELECT名,性别从开放数据源 ('SQLOLEDB','DataSource = NOLI\SQL2;UserID=myUserID;Password=myPassword').Organisation.dbo.Employees

来自 MSDN-

<块引用>

和 OPENROWSET 函数一样,OPENDATASOURCE 应该只引用访问的 OLE DB 数据源很少.定义链接服务器对于访问更多的任何数据源比几次.两者都不OPENDATASOURCE 或 OPENROWSET 提供链接服务器的所有功能定义,例如安全性管理和查询能力目录信息.所有连接信息,包括密码,必须每次提供OPENDATASOURCE 被调用.

Is there a TSQL command to connect to another server?

Or when you are in a Query Window, what are the Keyboard shortcuts to connect to another server and have a Query Window show up?

I have seen Ctrl+N pop up the Connect to Server dialog in some screens but when I am in a Query Window already and hit Ctrl+N it just opens up another Query Window.

The USE command lets you connect to other databases on the current server but is there a command that lets you connect to another server?

I am using SQL Server 2005.

解决方案

You can use OpenDataSource with a linked server

OpenDataSource(provider_name, init_string)

For example

SELECT
FirstName,
Gender
FROM
OpenDataSource (
'SQLOLEDB',
'DataSource = NOLI\SQL2;UserID=myUserID;Password=myPassword'
).Organisation.dbo.Employees

From MSDN-

Like the OPENROWSET function, OPENDATASOURCE should only reference OLE DB data sources that are accessed infrequently. Define a linked server for any data sources accessed more than several times. Neither OPENDATASOURCE nor OPENROWSET provide all the functionality of linked-server definitions, such as security management and the ability to query catalog information. All connection information, including passwords, must be provided every time that OPENDATASOURCE is called.

这篇关于连接到另一台服务器的 TSQL 命令 (SQL Server 2005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
SQL query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)