易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL Server连接远程数据源

SQL Server连接远程数据源的基本方法有下面三种:
OPENDATASOURCE
: The OPENDATASOURCE function is used to
specify connection information for a remote data source by specifying
the OLE DB provider and an initialization string. OPENDATASOURCE can be
used directly within a SELECT, INSERT, UPDATE, or DELETE statement.
 
OPENROWSET
: The OPENROWSET function is used to specify
connection information for a remote data source and the name of an
object that will return a result set (such as a stored procedure) or a
query that will return a result set. Like OPENDATASOURCE, OPENROWSET
can be used directly within a SELECT, INSERT, UPDATE, or DELETE
statement.
 
Linked servers
: A linked server is an object within SQL
Server that defines the connection properties of another SQL Server.
When defined, queries can connect to the remote server using a
four-part name, such as
SQLSrv1.AdventureWorks.person.Contact
The four-part name identifies the server (SQLSrv1), the database
(AdventureWorks), the schema (Person), and the object (Contact table).
Linked servers are explored in more depth in the final section of this
chapter.
 
其中OPENDATASOURCE和OPENROWSET方法一般用来做临时查询(ad hoc query),如果需要经常的查询远程数据,则建议创建linked servers。但是,默认情况ad hoc query 是禁用的,需要手动启动:
sp_configure ‘show advanced options’, 1;
GO
RECONFIGURE;
GO
sp_configure ‘Ad hoc Distributed Queries’, 1;
GO
RECONFIGURE;
 
然后,就可以使用OPENDATASOURCE 查询远程数据库了,OPENDATASOURCE 基本语法如下:OPENDATASOURCE ( provider_name, init_string )。示例代码如下:
SELECT *
from OPENDATASOURCE(‘SQLNCLI’,
‘Data Source=SQL08;Integrated Security=SSPI’)
.Sales.dbo.Customers
上述代码从SQL08服务器上读取Sales数据库的Customers表的内容。
 
也可以通过OPENROWSET方法查询远程数据库,OPENROWSET和OPENDATASOURCE方法相似,基本的差异是
OPENROWSET总是返回结果集,而OPENDATASOURCE方法除了可以返回结果


相关文档:

SQL Server 返回最后插入记录的id值

SQL Server 2000中,有三个比较类似的功能:他们分别是:SCOPE_IDENTITY、IDENT_CURRENT 和 @@IDENTITY,它们都返回插入到 IDENTITY 列中的值。
IDENT_CURRENT 返回为任何会话和任何作用域中的特定表最后生成的标识值。IDENT_CURRENT 不受作用域和会话的限制,而受限于指定的表。IDENT_CURRENT 返回为任何会话和作用域中的 ......

组合索引优化SQL续

昨天我说,用组合索引优化SQL,并不是最优的,这是因为在8亿的表上面有个等价的物化视图,这个物化视图可以代替我在之前在表上面建立的组合索引。
SQL> explain plan for SELECT distinct * from (select
  2   (PROD_9005_GDF_WK_SS_FDIM.PROD_4_NAME),
  3    PROD_9005_GDF_WK ......

在SQL SERVER 2008 中附加MDF&LDF

首先启动SQL SERVER的服务
连接后 在数据库上右键
选择附加。。。
点击 添加。。。
在跳出框内找到你的MDF文件位置 选中 添加进去
相同文件夹内的LDF文件自动加上
完成~~(*^__^*) 嘻嘻……
OK啦 呵呵
初学初学~希望也能帮到其他像我一样的初学者
大家一起加油吧!O(∩_∩)O~ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号