Recreating cluster index to another filegroup with DROP_EXISTING = ON

Alen Cappelletti 891 Reputation points
2021-10-15T09:29:07.333+00:00

Hi all,
I read some article about the subject...
and specifically for the

CREATE .... WITH (DROP_EXISTING = ON)

"
This means the non clustered indexes only have to be updated once (to include the new key column).
Not twice - first to use the physical rid and then again to use the new CI key.
The DROP_EXISTING clause tells SQL Server that the existing clustered index is being dropped but that a new one will be added in its place, letting SQL Server defer updating the nonclustered index until the new clustered index is in place..
Additionally, SQL Server won't rebuild the nonclustered index at all if the clustered index key doesn't change and is defined as UNIQUE, which isn't an obvious performance benefit of defining a clustered index as UNIQUE

"

But moving it to another filegroup, there are always the same benefits or the rule only applies to the same filegroup.
So, applying the syntax that I have reported, is it correct then act on clustered and then to the non-clustered ones, since I will not physically delete them before recreating them?

Thanks all, Alen

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dan Guzman 9,206 Reputation points
    2021-10-15T12:28:43.373+00:00

    But moving it to another filegroup, there are always the same benefits or the rule only applies to the same filegroup.
    So, applying the syntax that I have reported, is it correct then act on clustered and then to the non-clustered ones, since I will not physically delete them before recreating them?

    When you rebuild the clustered index with DROP_EXISTING=ON and the key definition is the same, the non-clustered indexes are not touched because the row locator (clustered index key plus uniqueifier when needed) does not change. The behavior is the same with or without a different filegroup.

    0 comments No comments

0 additional answers

Sort by: Most helpful