Prayer

在一般中寻求卓越
posts - 1256, comments - 190, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

关联表的更新

Posted on 2009-05-06 15:52 Prayer 阅读(468) 评论(0)  编辑 收藏 引用 所属分类: DB2
关联表更新sybase SqlServer和MS SqlServer的语法比较简单实用,相比DB2和Oracle就比较tu一点,而且要注意在更新的范围一定要有限制,否则关联之外的字段都会被更新为[null]:
UPDATE tab1 a
SET a.col1 = (select b.col1 from tab2 b where a.col2 = b.col2)
WHERE a.col2 IN (SELECT b.col2 FROM tab2 )


还有在子查询中的结果集对于必须是唯一的!
update tab1 a
set a.col1 = (select b.col1 from tab2 b where a.col2 = b.col2)
where ...

(select b.col1 from tab2 b where a.col2 = b.col2) 必须唯一。

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理