在數據表更新時,可能會出現一種情況,就是更新的內容是來源於其他表的,這個時候,update語句中就加了from,下面為一個范例:
update a set a.name=b.name,a.value=b.value from table1 a,table2 b where b.id='id2' and a.id=b.id
那么就出現一個問題了,如果同時更新兩張表,可以實現嗎?
比如下面的語句:
update a,c set a.name=b.name,a.value=b.value,c.value=b.value from table1 a,table2 b,table3 c where b.id='id2' and a.id=b.id and a.id=c.id
我嘗試的結果是,不可以兩張表同時更新,只能一張表一張表的更新(即上面的語句應該拆分成兩條,分別執行)。