有两张表,结构一样。表1,里面有数据
表2,里面有数据他们之间数据可能有重复(主键重复或整行都一样)现在要把表2的数据完全复制到表1里,有简单的办法吗?
(情况:表1是正式表,表2是测试表
在做程序时,错误的把数据都导进测试表了。
所以现在要把这些数据COPY回表1)

解决方案 »

  1.   

    truncate table 表1
    insert into 表1 select * from 表2
      

  2.   

    --清除表1中所有数据,并不记录日志
    truncate table 表1--将表2中所有数据导入表1
    insert into 表1 select * from 表2
      

  3.   

    insert 表1 select * from 表2 where not exists (select 1 from 表2,表1 where 表2.主键=表1.主键)
      

  4.   

    我的办法是先把表1重复的删掉,然后将表2全部insert进表1begin transactiondelete [表1] from [表2] where [表1].[主键字段] = [表2].[主键字段]insert into [表1] select * from [表2]commit
      

  5.   

    我这样写好不好呢?
    insert into  table_one select * from table_two where table_two.id not in(select table_one.id id from table_one inner join table_two on table_one.id=table_two.id);
    运行出来结果是可以的,但是应该效率不高吧,如何改?
    楼上有用not exists 的,但是我没运行出来