SQL SERVER 2008查詢其他資料庫

2021-09-06 18:55:55 字數 1718 閱讀 8232

1、訪問本地的其他資料庫

--

啟用ad hoc distributed queries--

exec sp_configure '

show advanced options

',1reconfigure

exec sp_configure '

ad hoc distributed queries

',1reconfigure

--使用完成後,關閉ad hoc distributed queries--

exec sp_configure '

ad hoc distributed queries

',0reconfigure

exec sp_configure '

show advanced options

',0reconfigure

--select * from opendatasource('sqloledb ','data source=ip(或servername);user id=登陸名;password=密碼 ').資料庫.dbo.表名(或檢視)

select

*from

opendatasource

(

'sqloledb ',

'data source=itvs;

user id=sa;password=sa')

.ansvsp.dbo.serv

2、訪問其他機器上的資料庫

(1)將遠端機器上的sql server遠端開啟

(2)將遠端機器上的防火牆關掉

select

*from

opendatasource

(

'sqloledb',

'data source=192.168.1.26;

user id=sa;password=sadan ')

.ansvsp.dbo.serv

內聯

select a.bah,a.mz,b.*

from

opendatasource

(

'sqloledb',

'data source=192.168.1.26;

user id=sa;password=sadan ')

.ansvsp.dbo.serv

as a inner

join db_local_table b on a.bah=

b.id collate chinese_prc_90_ci_ai;

--collate chinese_prc_90_ci_ai 保持等號兩邊的排序規則一致即可

修改

update b set b.fhsj=a.date_end from

opendatasource

(

'sqloledb',

'data source=192.168.1.26;

user id=sa;password=sadan')

.ansvsp.

[dbo

].[view_funeral_tr

]as a inner

join hzxxb b on a.id=b.bah collate chinese_prc_90_ci_ai where fhsj is

null;

SQLServer2008語句查詢

1 判斷資料庫是否存在 if exists select from sys.databases where name 資料庫名 drop database 資料庫名 2 判斷表是否存在 if exists select from sysobjects where id object id 表名 an...

SQL Server 2008 實施查詢優化建議

可以手動實施資料庫引擎優化顧問的建議,也可以在優化會話中自動實施。如果需要在實施建議之前檢查優化結果,請使用資料庫引擎優化顧問圖形使用者介面 gui 然後可以使用 microsoftsql servermanagement studio 手動執行資料庫引擎優化顧問在分析完工作負荷之後生成的 tran...

Sql Server 2008 收縮日誌

收縮日誌 alter database dnname set recovery with no wait goalter database dnname set recovery 簡單模式 gouse dnname godbcc shrinkfile n dnname log 11,truncate...