详细的用法已经注释在sql代码中了。这个是在sqlserver到sqlserver之间的倒数据。2005,2008,2012应该都是适用的。
--从远程服务器192.168.66.154上查询100条数据,然后导入到dbo.dquestiondata中 insert into dbo.dquestiondata select top 100 * from opendatasource('sqloledb','data source=192.168.6.154;user id=sa;password=xxxxxx').Answer.dbo.DQuestionData --opendatasource 是一个系统函数,第一个参数是Provider Name,第二个参数是Oledb链接字符串, --注意连接字符串里没有指定数据库;数据库名称,Schema,表名在opendatasource函数后面书写。 --执行上面的语句会报如下的错,原因是没有开启远程查询支持 --SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' --because this component is turned off as part of the security configuration for this server. --A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. --For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online. --解决办法1:在图形界面中,SQL Server 安全配置-->机能的安全配置-->开启远程查询Openrowset和opendatasource的支持 --解决办法2:用sp_confing系统存储过程,以命令行的方式开启 --首先必须开启‘show advanced options’高级选项,因为‘Ad Hoc Distributed Queries’属于高级选项 exec sp_configure 'show advanced options' ,1 reconfigure --下