Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Efficiently add columns to a columnstore table

$
0
0
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




Viewing all articles
Browse latest Browse all 7129

Trending Articles