SQLServer批量更新

ywxj_001發表於2019-11-20

1、直接用top N來實現批量更新

update top(1000) table1 set SysNo = 0 ,UpdateTime = getdate() where Status not in (-1,-2,-3,-4,-5,4) and StockStatus <> 2 and isnull(CaiSysNo,0) = 0 and SysNo = 1;


2、用中間表實現批量更新

select SysNo into table1_temp01

FROM    table1 

WHERE EXISTS (SELECT 1 FROM table1_History..table1_History a WHERE a.SysNo=table1.SysNo);


UPDATE TOP(5000)

from table1

where SysNo in

(select SysNo from table1_temp01);





來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22996654/viewspace-2665035/,如需轉載,請註明出處,否則將追究法律責任。

相關文章