sqlserver 多庫查詢

2021-09-26 14:25:42 字數 400 閱讀 6258

1,最近乙個專案使用sqlserver,使用sqlserver客戶端自帶得查詢工具,即選擇前1000行,生成得sql如下

select top 1000 *

from [slt].[dbo].[lr_base_company]

其中 slt是資料庫名,dbo是表示資料庫得表管理物件,lr_base_company是其中得乙個表。

測試,多庫查詢,新建乙個資料庫slt2,新建一張表test,插入測試資料,**如下

select top 1000 *

from [slt].[dbo].[lr_base_company] left join [slt2].[dbo].[test] on 1=1

發現查詢結果為兩個庫得並集。

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...