如题,表A和表B,结构完全一样,只是记录不同,想把A表中ID不在B表中的记录插到B表中,但是列数太多,能不能不用
Insert into b(char1,char2,char3...) From a (char1,char2,char3...) )

解决方案 »

  1.   

    insert b select * from a where a.id not in (select id from b)
      

  2.   


    create proc wsp
    @notfiter varchar(200)--不想写的字段,不能为空,也不能将所有字段都写上。
    as
    declare @fiter varchar(500)
    select @fiter=isnull(@fiter+',','')+name from sysobjects where id=object_id('A') and charindex(name,@notfiter)!>0
    exec('insert into B ('+ @fiter +') select '+@fiter+' from A where ~~~')
    --不想要id和name两个字段,这样写
    exec wsp 'id,name'