insert into 新表(id,.....)--字段同原来表结构原表1和表2做union,然后再插入到新表中,id为@@identity
对于有自增列的表,可以这么来合并:set identity_insert 表 oninsert Into 表(列) select * from 表xx set identity_insert 表 off
有重复数据,有2种,第一是表内本身有重复数据,第二个是两个表之间 有重复数据。这个可以去重。比如,下面的是去除表xx 和表yy,之间的重复:set identity_insert 表 oninsert Into 表yy(列) select * from 表xx where id not exists(select 1 from 表yy where 表yy.id = 表xx.id)set identity_insert 表 off
有重复数据,有2种,第一是表内本身有重复数据,第二个是两个表之间 有重复数据。这个可以去重。比如,下面的是去除表xx 和表yy,之间的重复:set identity_insert 表 oninsert Into 表yy(列) select * from 表xx where id not exists(select 1 from 表yy where 表yy.id = 表xx.id)set identity_insert 表 off他说的是数据重复,而不是id重复吧,怎么解决呢?
select *
from 表xx
set identity_insert 表 off
有重复数据,有2种,第一是表内本身有重复数据,第二个是两个表之间 有重复数据。这个可以去重。比如,下面的是去除表xx 和表yy,之间的重复:set identity_insert 表 oninsert Into 表yy(列)
select *
from 表xx
where id not exists(select 1 from 表yy where 表yy.id = 表xx.id)set identity_insert 表 off
有重复数据,有2种,第一是表内本身有重复数据,第二个是两个表之间 有重复数据。这个可以去重。比如,下面的是去除表xx 和表yy,之间的重复:set identity_insert 表 oninsert Into 表yy(列)
select *
from 表xx
where id not exists(select 1 from 表yy where 表yy.id = 表xx.id)set identity_insert 表 off他说的是数据重复,而不是id重复吧,怎么解决呢?