表数据追加插入SQL

johndiyang 2010-04-06 09:46:56
有表A和表B的表结构完全一致,A,B中有部分数据相同,如何把A中的数据追加插入到B表中?即,如果A表中的数据x在B表存在,不插入,如果不存在则插入B表。
...全文
125 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
幸运的意外 2010-04-06
  • 打赏
  • 举报
回复
insert B select * from A where not exists(select 1 from B where A.主键字段1=B.主键字段1 and A.主键字段2 = B.主键字段2 and.....)
心中的彩虹 2010-04-06
  • 打赏
  • 举报
回复

insert b select * from a except select * from b

except--是找出表A中有的表B中没有的数据
johndiyang 2010-04-06
  • 打赏
  • 举报
回复
多谢各路大侠~!
htl258_Tony 2010-04-06
  • 打赏
  • 举报
回复
--2005


insert b select * from A except select * from b
--小F-- 2010-04-06
  • 打赏
  • 举报
回复
insert B select * from A where not exists(select 1 from B where a.x=b.x)
ACMAIN_CHM 2010-04-06
  • 打赏
  • 举报
回复
insert into b select * from a
htl258_Tony 2010-04-06
  • 打赏
  • 举报
回复


insert B select * from A where not exists(select 1 from B where a.x=b.x)
chuifengde 2010-04-06
  • 打赏
  • 举报
回复
insert b select a.* from a left join b on a.key=b.key where b.key is null
bancxc 2010-04-06
  • 打赏
  • 举报
回复
trucate table b
insert into b
select * fro a

34,838

社区成员

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

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