SQLServer跨库操作—分布式操作语句
(2010-07-17 19:50:29)
|
?
?
OpenDataSource和OPENROWSET
n? 可以跨库批量操作数据
n? 可以读取文本、Excel和多种数据库
1、? 用openrowset连接远程SQL或插入数据
--查询示例
select * fromopenrowset('SQLOLEDB','sql服务器名';'用户名';'密码',数据库名.dbo.表名)
--导入示例
select * into 表 fromopenrowset('SQLOLEDB',数据库名.dbo.表名)
2、opendatasource
--查询远程表
??????SELECT *FROM opendatasource('SQLOLEDB','DataSource=ip/ServerName;User ID=登陆名password=密码' ).test.dbo.roy_ta
--把本地表导入远程表
??????insert opendatasource('SQLOLEDB','Data Source=ip/ServerName;UserID=登陆名password=密码').数据库.dbo.表名 select * from 本地表
?
?n 如果想用opendatasource 查询远程数据库,结果提示:SQL Server阻止了对组件 'Ad Hoc Distributed Queries' 的访问错误
解决方法:
启用Ad Hoc Distributed Queries:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
使用完成后,关闭Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!