我有个网站,我要经常从远程服务器上把一个表备份到本地电脑的SQL数据库中。
我一直是删除本地SQL上的这个表,然后利用企业管理器的导入把远程服务器的整个表再创建复制过来。随着数据的增加,花费的时间越来越长,请问高手是否有简单的办法只追加远程服务器的新增加的数据过来?

解决方案 »

  1.   

    如果只是追加.例如:
    insert into tb select * from servername2.dbname2.dbo.tb where id not in (select id from tb)也许这样的时间更长.不如清空表后全部插入来得快.
      

  2.   

    用链接服务器,再用Insert into,不要用Not IN,用Not Exists
      

  3.   

    http://blog.csdn.net/fredrickhu/archive/2009/09/20/4573837.aspx
    http://blog.csdn.net/fredrickhu/archive/2009/09/20/4573845.aspx
    http://blog.csdn.net/fredrickhu/archive/2009/09/20/4572176.aspx
      

  4.   

    我的做法是,將遠程服務器數據庫備份之后在本地機導入為另一個名字的數據庫
    然后在本地機做
    insert into tb select * from dbname2.dbo.tb where id not in (select id from tb) 這樣更加安全快捷
      

  5.   

    exec sp_addlinkedserver  'ITSV', ' ', 'SQLOLEDB', 'hc1' 
    exec sp_addlinkedsrvlogin  'ITSV', 'false',null, 'sa', '123456' 
    insert into tb select * from servername2.dbname2.dbo.tb where id Not Exists (select id from tb)是这样的吗?
      

  6.   

    还是这样处理方便。。
    数据量大的话,还可以做成JOB,每天闲时执行。
      

  7.   


    你远程服务器的表可以修改么?增加一个timestamp列吧
    之后每次只把最近更新的timestamp 拿过来
    CREATE TABLE ExampleTable (PriKey int PRIMARY KEY, timestamp)
    insert into ExampleTable select 1,null
    select * from ExampleTable
    select @@DBTSinsert into tb select ExampleTable where timestamp >(select max(timestamp) from tb )