sql update 批量修改 如何使用sqlserver快速批量更新數(shù)據(jù)?
如何使用sqlserver快速批量更新數(shù)據(jù)?是,例如,when and then語句可以實(shí)現(xiàn)批更新語句update tableuuuown SETcloumnuown=Case ID當(dāng)1然后是“a”當(dāng)
如何使用sqlserver快速批量更新數(shù)據(jù)?
是,例如,when and then語句可以實(shí)現(xiàn)批更新語句
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)
此批更新語句意味著更新clocolumnuown字段,clocolumn if ID=1uown=a,clocolumn if id=2uown=B,clocolumn if id=3u記住,實(shí)際上下面的where語句不是必需的,但是最好帶上
如果不加where條件,整個(gè)表的數(shù)據(jù)都會(huì)被更新,不滿足條件的相應(yīng)值會(huì)被設(shè)為默認(rèn)值(導(dǎo)致前n-1次執(zhí)行無效,保留為第n次)
如果帶where條件,則不會(huì)出現(xiàn)這種情況
使用update修改數(shù)據(jù)庫數(shù)據(jù),如果結(jié)果集是多個(gè),則更方便批量修改。語法格式如下:update table set column=change The value where filter condition示例:update table set a=1--將表中a列的值更改為1 update table set a=1 where b=2--將表中b=2列記錄中a列的值更改為1