declare
begin
for i in (select * from emp)
loop
if i.sal=1300 then
update emp
set sal=13000;
end if;
end loop;
end;
This code
While some of these solutions are workable its not a one size fits all solution. I ran into a scenario where we had to set an xml/nvarchar(max) field to null on a table that has +50 M records. This is an excerpt of the code
begin
declare @rows int,
@y int = 2020,
@m int = 1;
set @rows = 1;
while (@rows > 0)
begin
update top (500) cr
set [xml] = null
from [dbo].[customer] cr with(index(ix_customer_reportdt))
where year([reportdt]) = @y
and month([reportdt]) = @m
and [xml] is not null;
set @rows = @@rowcount;
end
end