大量數據表的備份
一、對于表內的數據量非常大(上百萬條記錄)可以創建連接服務器如下語句
exec sp_addlinkedserver 'server','','SQLOLEDB','192.168.1.40'
exec sp_addlinkedsrvlogin 'server','false',null,'用戶名','密碼'
導入語句:
select * into 表 from 'server'.數據庫名.dbo.表名
以后不再使用時刪除鏈接服務器
exec sp_dropserver 'server','droplogins'
二、如果只是臨時訪問,可用openrowset
導入語句:
select * into 表 from openrowset('SQLOLEDB','sql服務器名';'用戶名';'密碼',數據庫名.dbo.表名)
在執行上面語句前要先執行下面的語句
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
在導入語句執行完成后在執行下面的語句把AD Hoc Distributed 關閉
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
如果把導入語句寫在SqlCommand里執行,需要注意CommandTimeOut的設置。默認是30秒。

浙公網安備 33010602011771號