Is there a way to automatically move clustered indexes A on one filegroup, and all nonclustered indexes to a different filegroup B upon DDL creation? We have developers constantly creating tables/indexes, and would like a way to automate this in dev environment. We have an old SAN Hard drive, and in some cases separating indexes on different filegroups may optimize performance, according to our DBA.


| improve this question | | | | |

Clustered index is just a well arranged table. When we create clustered index on heap, it arrange data of the tables based on key column. So moving clustered index means you are moving table to different file group.

There’s no inbuilt feature in SQL Server to automatically move indexes to specific file group when we create index, instead we can write index maintenance script to move indexes to specific file group based on index type or we'll have to specify file group while we are creating indexes.

Also, this link will help, https://stackoverflow.com/questions/55187160/automatically-create-indexes-in-different-filegroup-edit-publish-profile-script

| improve this answer | | | | |

As mentioned in previous answers, there is no inbuilt feature to create non-clustered index on a different filegroup however I can think of creating multiple filegroups specifically for Index and move non-clustered indexes to those filegroups based on certain criteria(size, frequency of usage. LUN etc.). It would be time consuming task for the first time as all the index will be moved at one time however later on you can schedule a task on weekly basis(on weekend) to move newly created indexes to index filegroups. This would ensure that all non-clustered indexes and tables are on separate filegroups.

As far as script for movement of non-clustered index is concerned, you may refer this article as well as this one. And as already highlighted by Mr. Rajesh - clustered index doesn't have separate storage so, moving clustered index is as good as moving the table itself.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy