1 delete from 
         table2
  where 
         (tabel2.f1 not in (select f1 from table1) 
          and table2.f2 not in (select f2 from table1))2 insert into table2 (select * from table1 where table1.f1 not in (select f1 from table2) and table1.f2 not in (select f2 from table2))

解决方案 »

  1.   

    delete from  table2 a
    where not exists(select * from table1 where f1=a.f1 and f2=a.f2)
    insert table2 select * from table1 a
    where not exists(select * from table2 where f1=a.f1 and f2=a.f2)
      

  2.   


    delete b
    from table2 b 
    left join table1 a on a.f1=b.f1 and a.f2=b.f2
    where a.f1 is null and a.f2 is null
      

  3.   

    在table1上加个触发器,
    当table1增加,修改,删除时,自动写table2表。
    应该很简单。