A表和B表,A表为历史表,B表为新表,现在想将B表放入到A表中,但是如果A中存在B中的记录则更新A中的记录,否则在A中插入新的记录,各位有啥高招吗?

解决方案 »

  1.   

    如果A表没有primary key 或者unique key,新建一个.然后
    replace a select * from b
      

  2.   

    分两步。
    1。 update a set a.fd=b.fd where a.id=b.id ....
    2. insert into a select * from b where id > (select max(id) from a).
        [align=center]====  ====
    [/align]
    .
    贴子分数<20:对自已的问题不予重视。
    贴子大量未结:对别人的回答不予尊重。
    .
      

  3.   

    replace into ....To know more about this statement,read particular content on the document.
      

  4.   

    假设A、B两表以ID为KEY字段
    update a set a.fd=b.fd where a.id=b.id 
    insert into a select b.* from b left join a on a.id=b.id where isnull(b.id)
      

  5.   


    insert into a select b.* from b left join a on a.id=b.id where isnull(a.id)