跨伺服器資料庫拷貝資料

2021-06-13 22:52:06 字數 1200 閱讀 3101

就在剛才我做了一件很讓人頭痛的事,不知道大家有沒有遇到過,就是一不小心把資料庫中的某個表裡的資料全刪除了,本來是想通過過濾條件去刪除一些不要的資料的,可是由於手速太快,條件還沒有選中,就按下了f5 鍵,一下子不知道如何是好!最後我上網也找了一些方法去解決這樣的問題,最終還是被我找到了!如下

1.啟用ad hoc distributed queries:

exec sp_configure 'show advanced options',1

reconfigure

exec sp_configure 'ad hoc distributed queries',1

reconfigure

2.執行資料的拷貝:

sql語句實現跨sql server資料庫操作例項 - 查詢遠端sql,本地sql資料庫與遠端sql的資料傳遞

(1)查詢192.168.1.1的資料庫(tt)表test1的資料

select * from opendatasource('sqloledb','server=192.168.1.1;uid=sa;pwd=123456;database=tt').tt.dbo.test1

(2)從192.168.1.2的資料庫(tt)表test2插入192.168.1.1資料庫(tt)的表test1去

insert into opendatasource('sqloledb','server=192.168.1.1;uid=sa;pwd=123456;database=tt').tt.dbo.test1 (id,[name],password) select id,[name],password

from opendatasource('sqloledb','server=192.168.1.2;uid=sa;pwd=123456;database=tt').tt.dbo.test2

3.為了安全

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

exec sp_configure 'ad hoc distributed queries',0

reconfigure

exec sp_configure 'show advanced options',0

reconfigure

這樣就完成了跨伺服器進行資料的拷貝,相信這個方法肯定能幫助我們在更加有效的去運算元據庫

通過伺服器命令批量拷貝資料庫

首先在控制台輸入以下命令,啟用額外的資料庫拷貝命令 不是群集也可以用 set config cluster admin on 1 無需重啟伺服器,以下命令就可以用於拷貝資料庫了 cl copy servera db1.nsf serverb db2.nsf 將 servera 上的 db1 新建拷貝...

跨資料庫 跨伺服器查詢

if notexists select srvname from master dbo sysservers where srvname vlinkinadmin begin exec sp dropserver server vlinkinadmin droplogins droplogins 增...

跨資料庫 伺服器匯入資料

1.跨資料庫匯入資料 資料庫中表已建立 1 insert into 資料庫 所有者 表 字段 select 字段 from 其它資料庫 所有者 表 where 條件 資料庫中表未建立 2 select into 資料庫 所有者 表 字段 from 其它資料庫 所有者 表 where 條件 2.跨伺服...