在數(shù)據(jù)表更新時,可能會出現(xiàn)一種情況,就是更新的內(nèi)容是來源于其他表的,這個時候,update語句中就加了from,下面為一個范例:
1
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
那么就出現(xiàn)一個問題了,如果同時更新兩張表,可以實現(xiàn)嗎?
比如下面的語句:
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
我嘗試的結(jié)果是,不可以兩張表同時更新,只能一張表一張表的更新(即上面的語句應(yīng)該拆分成兩條,分別執(zhí)行)。