批量更新的问题

sxr520cwx 2009-08-05 03:10:08
我有两张表,表A1和表A2
表A1
num content1
4 df
2 hy
1 df
3 hy
6 df
5 hy
表A2
num content2
1 001
2 002
3 003
4 004
5 005
6 006
我想实现将表内A1的content1批量更新为和A2表content2内一样,结果A1变为
表A1
num content1
4 004
2 002
1 001
3 003
6 006
5 005

update A1 set content1 = ??
...全文
55 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
weichaozu131083 2009-08-05
  • 打赏
  • 举报
回复
万一哪一天需要移植到其它类型数据库上去你就知道痛苦了,
黄_瓜 2009-08-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 weichaozu131083 的回复:]
尽量用标准SQL语句写,上面的update from是MSSQL扩展的,并非标准SQL

update A1 set content1 = (
    select s.content2 from A2
    where A1.num=s.num
)
[/Quote]
--简单就行
update  A1  set  content1  =  A2.content2
from A2
where A1.num=A2.num

weichaozu131083 2009-08-05
  • 打赏
  • 举报
回复
update A1 set content1 = (
select s.content2 from A2 s
where A1.num=s.num
)
weichaozu131083 2009-08-05
  • 打赏
  • 举报
回复
尽量用标准SQL语句写,上面的update from是MSSQL扩展的,并非标准SQL

update A1 set content1 = (
select s.content2 from A2
where A1.num=s.num
)
昵称被占用了 2009-08-05
  • 打赏
  • 举报
回复
省点

update  A1  set  content1  =  A2.content2
from A2
where A1.num=A2.num
htl258_Tony 2009-08-05
  • 打赏
  • 举报
回复
update  A1  set  
content1 = a2.content2
from A2
where a1.num=a2.num
昵称被占用了 2009-08-05
  • 打赏
  • 举报
回复
update  A1  set  content1  =  A2.content2
from A1,A2
where A1.num=A2.num

22,294

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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