我写了一段代码, 效率很差.
敬请帮忙!  谢谢.

解决方案 »

  1.   

    表1和表2中本来就有重复的记录吗??
    如果两个表本来就没有重复的记录,担心合并到一起后会有重复记录
    insert into 表1 select * from 表2 where 某关键字 not in (select 某关键字 from 表1)
      

  2.   

    你是说将表数据合并吗?
    insert into TableB(.,.,.,.,.) selct .,.,.,.,. from TableA where ID not in (select ID from TableB)
    //where后面的条件自己加上
      

  3.   

    不在一个数据库中, 我先用临时表把另外一个库表拷过来,然后用了insert into tableA select * from TableB where id not in (select id from tableA).  但效果很差, 容易中断.
      

  4.   

    INSERT INTO tableA SELECT * FROM tableB WHERE NOT EXISTS (SELECT * FROM tableA WHERE tableA.ID=tableB.ID)
      

  5.   

    放二个ADOConnection1,连两个不同的access
    然后从一库中取数据INSERT 到另外的库中去,INSERT的时候判断是不是有重复记录
      

  6.   

    smiler007(笑一笑)和Kshape([伟大的大伟!]) 的就可以解决了。结贴吧。
      

  7.   

    先连接一个access文件,执行下面的SQL就可以导数据了。用adoQuery执行的话,先adoQuery.ParamCheck := False; 例:将c:\db2.mdb的表1 导入到当前的access中
    Insert Into 表1
    SELECT * FROM [;database=C:\db2.mdb;pwd=填入密码].表1
      

  8.   

    如果用ADO的算法好象每次要对TABLEA做一个循环这样运算次数是A.recordcount*B.recordcount
    下面的算法可能并不省时,代码也多但能避免中间的中断
    先对TABLEA和TABLEB排序
    然后将两个表各放入一个链表
    再将两个有序链表合并成一个有序链表
    最后将有序链表存在数据库中
    唯一的优点是事务分开执行每一步不太费时,
      

  9.   

    http://community.csdn.net/Expert/topic/3835/3835676.xml?temp=.8674127
      

  10.   

    procedure TForm1.Button3Click(Sender: TObject);
    begin
      adoquery1.Close;
      adoquery1.SQL.Clear;
      adoquery1.SQL.Add('delete from b where sfzh1 in (select sfzh1 from b group by sfzh1 having count(*)>1)');
      adoquery1.Open;
    end;
      

  11.   

    procedure TForm1.Button4Click(Sender: TObject);
    begin
      adoquery1.Close;
      adoquery1.SQL.Clear;
      adoquery1.SQL.Add('alter table b add idMytest int identity(1,1)');
      adoquery1.ExecSQL;  adoquery1.Close;
      adoquery1.SQL.Clear;
      adoquery1.SQL.Add('delete from b where sfzh1 in (select sfzh1 from b where b.idMytest<idMytest '+
                        'group by sfzh1 having count(*)>1)');
      adoquery1.ExecSQL;  adoquery1.Close;
      adoquery1.SQL.Clear;
      adoquery1.SQL.Add('alter table b drop column idMytest');
      adoquery1.ExecSQL;end;