1.開通分布式查詢許可權
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'ad hoc distributed queries',1
reconfigure
2.查詢
select * from
openrowset( 'sqloledb ', 'ip位址(伺服器名)'; '使用者名稱'; '密碼',[資料庫名].[dbo].[表名]) a
, openrowset( 'sqloledb ', 'ip位址(伺服器名)'; '使用者名稱'; '密碼',[資料庫名].[dbo].[表名]) b
where *** group by *** order by count(1) desc
3.然後換查詢條件,然後修改ip、 庫名和表名。
4.關閉
exec sp_configure 'ad hoc distributed queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
SQLServer跨庫查詢
用openrowset連線遠端sql或插入資料 如果只是臨時訪問,可以直接用openrowset 查詢示例 select from openrowset sqloledb sql伺服器名 使用者名稱 密碼 資料庫名.dbo.表名 在跨庫查詢時需要啟用ad hoc distributed querie...
SQL Server跨庫查詢
方式一 語句select from 資料庫a.dbo.表a a,資料庫b.dbo.表b b where a.field b.field dbo 可以省略 如 select from 資料庫a.表a a,資料庫b.表b b where a.field b.field 方式二 在乙個資料庫掛上另乙個資料...
sql server跨庫查詢
方式一 dbo可以省略 select from 資料庫a.dbo.表a a,資料庫b.dbo.表b b where a.field b.field 方式二 在乙個資料庫掛上另乙個資料庫的外鏈 對映乙個遠端資料庫 exec sp addlinkedserver 遠端資料庫的ip或主機名 n sql s...