insert into 数据库.表
select * from
openrowset ( ' SQLOLEDB ' , ' sql服务器名 ' ; ' 用户名 ' ; ' 密码 ' , 源数据库名 . dbo . 表名 )
where 条件
例:
insert into abc1
select * from
openrowset ( ' SQLOLEDB ' , ' SQL1 ' ; ' sa ' ; ' 123456 ' , [Test].dbo.abc1 )
需要启用"Ad Hoc Distributed Queries",不然汇报下面错误
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。
启用"Ad Hoc Distributed Queries"需要使用sp_configure系统存储过程进行配置。
使用sa或具有sysadmin角色的登录名连接到SQL Server执行以下命令以启用"Ad Hoc Distributed Queries"
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO