连接到另一台服务器的 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Number of working days between two dates(两个日期之间的工作日数)
How do I use dateadd to get the first day of last year?(如何使用 dateadd 获取去年的第一天?)
SQL- Count occurrences of a specific word within all stored procedures(SQL- 计算所有存储过程中特定单词的出现次数)
SQL query to make a column of numbers a string(使一列数字成为字符串的 SQL 查询)
T-SQL: Best way to replace NULL with most recent non-null value?(T-SQL:用最新的非空值替换 NULL 的最佳方法?)
Count days in date range with set of exclusions which may overlap(使用一组可能重叠的排除项计算日期范围内的天数)