I have a columnstore table with 30 columns and 16M rows and I wanted to add a column using update statement and found that it took quite a long time.
Here is the code:
alter table tab1
add value_lag varchar(3)
update tab1
set a1.value_lag= b1.value
from tab1 a1
left join tab1 b1
on a1.id = b1.id
and a1.Period = b1.period + 1
Using window function and index won't accelerate the process much, I'm wondering what's the best way to do it? Or should I just keep a separate table for the value_lag? I use sql server 2016 on win 10 64bit
Here is the code:
alter table tab1
add value_lag varchar(3)
update tab1
set a1.value_lag= b1.value
from tab1 a1
left join tab1 b1
on a1.id = b1.id
and a1.Period = b1.period + 1
Using window function and index won't accelerate the process much, I'm wondering what's the best way to do it? Or should I just keep a separate table for the value_lag? I use sql server 2016 on win 10 64bit