------------------------------------------------------------
--这段先执行
exec sp_configure ‘show advanced options‘,1
reconfigure
exec sp_configure ‘Ad Hoc Distributed Queries‘,1
reconfigure
------------------------------------------------------------
--这里写要执行的SQL语句
select *
from opendatasource(‘SQLOLEDB‘,‘server={server};uid={uid};pwd={pwd}‘).[DataBaseName].dbo.TableName
------------------------------------------------------------
--语句运行完以后执行这段关闭配置
exec sp_configure ‘Ad Hoc Distributed Queries‘,0
reconfigure
exec sp_configure ‘show advanced options‘,0
reconfigure
------------------------------------------------------------
SQL SERVER 执行远端数据库的SQL命令
时间: 2024-11-06 09:50:56