关联表的更新

关联表更新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) 必须唯一。

你可能感兴趣的:(关联表的更新)