sql 批量修改一個(gè)列的數(shù)據(jù) 關(guān)于sql語(yǔ)句如何批量修改數(shù)據(jù)?
關(guān)于sql語(yǔ)句如何批量修改數(shù)據(jù)?是,例如,when and then語(yǔ)句可以實(shí)現(xiàn)批更新語(yǔ)句update tableuuuown SETcloumnuown=Case ID當(dāng)1然后是“a”當(dāng)2然后是“B
關(guān)于sql語(yǔ)句如何批量修改數(shù)據(jù)?
是,例如,when and then語(yǔ)句可以實(shí)現(xiàn)批更新語(yǔ)句
update tableuuuown SET
cloumnuown=Case ID
當(dāng)1然后是“a”
當(dāng)2然后是“B”
當(dāng)3然后是“C”
end
where ID in(1,2,3)
此批更新語(yǔ)句意味著更新clocolumnuown字段,clocolumn if ID=1uown=a,clocolumn if id=2uown=B,clocolumn if id=3uown=C
記住,事實(shí)上,結(jié)束后的where語(yǔ)句不是必需的,但最好帶上它
如果不添加where條件,整個(gè)表的數(shù)據(jù)都會(huì)被更新,不滿足條件的相應(yīng)值會(huì)被設(shè)置為默認(rèn)值值(導(dǎo)致前n-1次執(zhí)行無(wú)效,第n次保留)
如果帶where條件,則不會(huì)發(fā)生這種情況
使用update更新和修改數(shù)據(jù)庫(kù)數(shù)據(jù)。如果更改的結(jié)果集是多個(gè),則為批量修改。
例如:update table set a=1--將表中a列的值更改為1。Update table set a=1 where b=2——將表中b=2列的記錄中a列的值更改為1