Search code examples
sqlsql-serverindexingsql-server-2016clustered-index

Move an existing Clustered columnstore index into a different file group


I am trying to move an existing Clustered Columnstore Index from one file group to another file group but couldn't find any command to do that.

Code what I have tried:

ALTER TABLE CCSI ON [dbo].[t179_s1_LOSS_ByEvent_ORIGINAL_440F6776-6185-4416-89D8-B69334457B25] 
WITH ( MOVE TO FG_1 );

Error:

Msg 156, Level 15, State 1, Line 281 Incorrect syntax near the keyword 'ON'.

Msg 319, Level 15, State 1, Line 281 Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.


Solution

  • Just like a clustered index, recreate it on the target filegroup with DROP_EXISTING. eg

    create table foo(id int, a int)
    create clustered columnstore index cci_foo on foo
    
    go
    
    create clustered columnstore index cci_foo 
    on foo
    with (drop_existing=on)
    on fg2