关于合并两个表的问题向各位高手请教???

ye12 2006-04-17 04:24:41
问题是这样的,有两个表,A和B ,他们的结构是一样的,现在的问题是可能表A有10记录,但是表B已经有20条记录了,如何将表B中这10条记录加入到表A中内。
...全文
117 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
dp_555 2006-04-17
  • 打赏
  • 举报
回复
友情接分。。。
hyrongg 2006-04-17
  • 打赏
  • 举报
回复
create table ta(id int,num int)
insert into ta select 1,1
union all select 2,2
union all select 3,3
union all select 4,4


create table tb(id int,num int)
insert into tb select 1,1
union all select 2,2
union all select 3,3
union all select 4,4
union all select 5,5
union all select 6,6
union all select 7,7
union all select 8,8

insert into ta
select id,num from tb where id not in(select id from ta)

select * from ta

drop table ta
drop table tb

ye12 2006-04-17
  • 打赏
  • 举报
回复
不知改成记录集,不知是否还是可以用能上操作呢
xeqtr1982 2006-04-17
  • 打赏
  • 举报
回复
防止插入重复的数据。
ye12 2006-04-17
  • 打赏
  • 举报
回复
insert into a select * from b where not exists(select 1 from a where a.id=b.id)
我请问下,其中的select 1 from a where a.id=b.id这句中的1是什么作用,可以说一下吗。
拓狼 2006-04-17
  • 打赏
  • 举报
回复
insert into a select * from b where not exists(select 1 from a where a.id=b.id)
ye12 2006-04-17
  • 打赏
  • 举报
回复
如何设定条件,可以说清楚一点吗,先谢了
xeqtr1982 2006-04-17
  • 打赏
  • 举报
回复
insert into b select * from a?

还是

select * from b
union all
select * from a

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧