大量数据表的备份

一、对于表内的数据量非常大(上百万条记录)可以创建连接服务器如下语句

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秒。

 

posted @ 2010-04-24 14:04  Xingsoft  阅读(445)  评论(0编辑  收藏  举报