insert 正式表
select * 
from 临时表 a  left join 正式表 b on a.pk=b.pk
where b.pk is null

解决方案 »

  1.   

    insert 正式表
    select distinct * from 临时表  a
    where not exists (select * from 正式表 where pk=a.pk)
      

  2.   

    bcp+触发器就行了.--触发器用类似这样的处理
    create tr_process on 表
    instead of insert
    as
    insert 表 select * from inserted a
    where not exists(
        select * from 表 where 主键=a.主键)
    go
    --bcp导入的时候,使用FIRE_TRIGGERS选项允许触触发器bcp "库名.dbo.表名" in "c:\a.txt" /S"sql服务器名" /U"sa" /P"密码" /c /h "FIRE_TRIGGERS"
      

  3.   

    --如果要实现存在的更新,不存在的导入,将触发器改为
    create tr_process on 表
    instead of insert
    as
    update a set 字段1=i.字段1,字段2=i.字段2,....字段n=i.字段n
    from 表 a,inserted i
    where i.主键=a.主键insert 表 select * from inserted a
    where not exists(
        select * from 表 where 主键=a.主键)
    go
      

  4.   

    --或者把触发器改为:--如果要实现存在的更新,不存在的导入,将触发器改为
    create tr_process on 表
    instead of insert
    as
    delete a 
    from 表 a,inserted i
    where i.主键=a.主键insert 表 select * from inserted a
    go