update table1
set ((f1,f2,f3)=(select f1,f2,f3 from table2 where id=table1.id))
在sqlserver上怎么实现呢?
6 个解决方案
#1
update table1
set f1 = t.f1,
f2 =t.f2,
f3 =t.f3
from table2 t
where table1.id = t.id
#2
update table1
set f1 = table1.f1,
f2 =table1.f2,
f3 =table1.f3
from table2
where table1.id = table1.id
#3
这样的不可以 只能一次更新一个字段
update a set col1=b.col and co2=b.col2 from a,b where a.id=b.id
#4
这个可以,但被更新的表如果有where 字句怎么弄?
update table1
set f1 = t.f1,
f2 =t.f2,
f3 =t.f3
from table2 t
where table1.id = t.id
where table1.fx='aaa'
#5
update table1
set f1 = t.f1,
f2 =t.f2,
f3 =t.f3
from table2 t
where table1.id = t.id
and table1.fx='aaa'
#6
谢谢!
#1
update table1
set f1 = t.f1,
f2 =t.f2,
f3 =t.f3
from table2 t
where table1.id = t.id
#2
update table1
set f1 = table1.f1,
f2 =table1.f2,
f3 =table1.f3
from table2
where table1.id = table1.id
#3
这样的不可以 只能一次更新一个字段
update a set col1=b.col and co2=b.col2 from a,b where a.id=b.id
#4
这个可以,但被更新的表如果有where 字句怎么弄?
update table1
set f1 = t.f1,
f2 =t.f2,
f3 =t.f3
from table2 t
where table1.id = t.id
where table1.fx='aaa'
#5
update table1
set f1 = t.f1,
f2 =t.f2,
f3 =t.f3
from table2 t
where table1.id = t.id
and table1.fx='aaa'
#6
谢谢!