首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

如何将查询出来的很多条记录插入到另一个表中去?

2012-01-23 
怎么将查询出来的很多条记录插入到另一个表中去??我有两个表分别是表1和表2,表2里面装的是已经提取的记录,

怎么将查询出来的很多条记录插入到另一个表中去??
我有两个表分别是表1和表2,表2里面装的是已经提取的记录,每一次取记录的时候要有一个筛选,就是说选的记录不在表2里面。提取表1里面的记录再存到表2里面,表示已经提取过了。请问有什么sql可以达到这样的效果
我有这样一句     insert   into   表2   values(select   *   from   表1   where   关键字段   not   in   (select   关键字段   from   表2))

[解决办法]
insert into 表2
select * from 表1 where 关键字段 not in (select 关键字段 from 表2)

[解决办法]
insert into 表2
select * from 表1 where 关键字段 not in (select 关键字段 from 表2)
[解决办法]
insert into 表2
select distinct * from 表1 where not exists(select 1 from 表2 where 表1.关键字段=表2.关键字段)

[解决办法]
insert into 表2
select * from 表1 where 关键字段 not in (select 关键字段 from 表2)

--or
insert into 表2
select * from 表1 where not exists(select 1 from 表2 where 表1.关键字段=表2.关键字段)


我要取的是前5000个不重复的 distinct top 5000 关键字段 应该是这样的吧?
-------------------------
对。。是这样。。

热点排行