两台数据库服务器之间表中数据定时导入:1 生产主机GGJBHT 上的thdata表 定时  往备份机的thdata表中传入数据,用下列方式已创立好连接服务器EXEC sp_addlinkedserver
      @server='DBVIP',-- 被访问的服务器别名
      @srvproduct='',
      @provider='SQLOLEDB',
      @datasrc='192.168.1.10'   --要访问的服务器
 
EXEC sp_addlinkedsrvlogin
     'DBVIP', --  被访问的服务器别名
     'false',
     NULL,
     'sa', --帐号
     '010' --密码生产机THDATA表中ID在备份机thdata中没有则就导入,
采取这种思路写入下列代码:INSERT INTO thdata as a     
SELECT * from  DBVIP.GGJBHT.dbo.thdata  as  b
where b.ID > a.ID 
运行不能通过,怎么写呢?有别的方式可以实现吗?

解决方案 »

  1.   

    INSERT INTO  a   
    SELECT b.* from thdata as a, DBVIP.GGJBHT.dbo.thdata as b
    where b.ID > a.ID  
      

  2.   

    INSERT INTO  a   
    SELECT b.* from thdata as b, DBVIP.GGJBHT.dbo.thdata as a
    where b.ID > a.ID  
      

  3.   

    INSERT INTO  a   
    SELECT b.* from thdata as a, DBVIP.GGJBHT.dbo.thdata as b
    where b.ID > a.ID  ---这种写法,我感觉有些不对
      

  4.   

    sql 2005以上的话 就用merge
    merge需要定义目标表和源表 然后判断
    如果目标表有 源表没有 如何如何 等等
    具体可以网上搜索一下merge的语法
      

  5.   

    INSERT INTO  thdata /*你要插入的所在服务器上的数据库*/
    SELECT b.* from thdata as b, DBVIP.GGJBHT.dbo.thdata as a
    where b.ID > a.ID  
      

  6.   


    INSERT INTO thdata   
    SELECT b.* from thdata as a, DBVIP.GGJBHT.dbo.thdata as b
    where b.ID > a.ID