关于两个表的问题

liangyuan198412 2007-03-14 06:11:27
有表A中一个字段DWDM(值:12 10 45 20)
有表B中一个字段DWDM(值:12 10 45 20 23 25)
DWDM是两表的主健


怎么样把B表的数据覆盖的A表中
...全文
194 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
marco08 2007-03-14
  • 打赏
  • 举报
回复


create table A(DWDM int)
insert A select 12
union all select 10
union all select 45
union all select 20
go
create table B(DWDM int)
insert B select 12
union all select 10
union all select 45
union all select 20
union all select 23
union all select 25
go

insert A
select DWDM from B as tmp
where not exists(select 1 from A where DWDM=tmp.DWDM)

select * from A
saiwong 2007-03-14
  • 打赏
  • 举报
回复
insert into A
select * from B where DWDM not in (select DWDM from A)
david_anwei 2007-03-14
  • 打赏
  • 举报
回复
insert A
select * from B where DWDM not in (select DWDM from A)
zheninchangjiang 2007-03-14
  • 打赏
  • 举报
回复
你到现在还没有描述清楚两个表主键是关系?
liangyuan198412 2007-03-14
  • 打赏
  • 举报
回复
不能清楚的,还有其他的呢 !
ankor 2007-03-14
  • 打赏
  • 举报
回复
TRUNCATE table A
insert A select * from B
也可以..`
mengmou 2007-03-14
  • 打赏
  • 举报
回复
delete A
where DWDM not in (select DWDM from B)
liangyuan198412 2007-03-14
  • 打赏
  • 举报
回复
如果是把存在于A表不在B表中数据一起删掉的话怎么做!!
zheninchangjiang 2007-03-14
  • 打赏
  • 举报
回复
--maybe
update a set dwdm=b.dwdm from tablea a join tableb b on charindex(a.dwdm,b.dwdm)=1
mengmou 2007-03-14
  • 打赏
  • 举报
回复
insert A
select * from B where DWDM not in (select DWDM from A)

34,588

社区成员

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

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