Hi guys
I need to update one column for approx. 31k record. I would like to do this in a batch of 5000. What is the best way of updating the record.I started like this, but not sure whether this will be the best way of doing it.
use qnt_ikru_odb
go
if (object_id ('tempdb..#t1')is not null)
begin
drop table #t1
end
create table #t1
(
customer_id varchar(24) not null,
loyalty_program varchar(20) null,
customer_profile_id int not null,
id int identity(1,1),
customer_updated_datetime datetime null
)
insert into #t1
select customer_id,loyalty_program,customer_profile_id,customer_updated_datetime from [QNT_IKRU_ODB]..customer_profile
where loyalty_program='ACTIVE'
and customer_id in
(
all customer_id(approx. 31k details)
)
declare @rowcount int,@batch int,@id int
select @rowcount=count(*) from #t1
set @batch=5000
while(@rowcount >0)
begin
begin transaction
update top (5000)a
set mobile_telephone=NULL,
b.customer_updated_datetime=getutcdate()
from customer_address a with(nolock)
join
#t1 b on
a.customer_profile_id=b.customer_profile_id
join
customer_profile c
on b.customer_profile_id=c.customer_profile_id
where c.customer_id in (select customer_id from #t1)
select @rowcount=@rowcount-@batch
commit transaction
end