damugua
--一、操作提权
/*
--启用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
*/

declare @A varchar(100)=null;
declare @B varchar(100)=null;

--查询本地库数据信息
select top 1 @A =sum(NowNum)  from table1

--启动远程服务器连接,添加一次就可以
--EXEC sp_addlinkedserver \'服务器地址\',N\'SQL Server\'        --将远端数据库映射到本地数据
--EXEC sp_addlinkedsrvlogin \'服务器地址\', \'false\', NULL, \'数据库账号\', \'密码\'  -- 启动链接远端服务器 

--二、跨数据库查询数据
select top 1  @B= sum(NowNum) from [服务器地址].数据库名.dbo.[表名]

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2021-10-10
  • 2022-01-12
  • 2021-12-26
相关资源
相似解决方案