Wednesday, March 28, 2012

Index rebuilds question

Hi,
My question is: How do you know when an index is
actually finished being rebuilt? I run a script that goes
through and searches for indexes that need rebuilding
because of fragmentation or "staleness" and then run DBCC
DBREINDEX on them. The DBCC command returns that the
index "is being rebuilt" and then moves on to the next
one. Is there anywhere I can query to see when the index
is actually finished being rebuilt? I'd like to know this
so I can then run an UPDATE STATISTICS on it. Right now
the procedure dies occasionally because it attempts to do
the stats update before the other process is complete.
I realize that I can schedule the stats update as a
separate process later in the evening (my current
workaround) but I was curious to see if there was another
alternative. Thanks!
-DanDan,
Not sure how your getting into this situation as the next line of code
should not execute until the DBCC DBREINDEX is completed. The first line
must execute before the next one can start. In either case there is no need
to update the stats on an index that you just rebuilt as it is done as part
of the DBREINDEX.
--
Andrew J. Kelly
SQL Server MVP
"Dan Wunder" <dwunder@.pentontech.com> wrote in message
news:019a01c39404$8b5ace70$a301280a@.phx.gbl...
> Hi,
> My question is: How do you know when an index is
> actually finished being rebuilt? I run a script that goes
> through and searches for indexes that need rebuilding
> because of fragmentation or "staleness" and then run DBCC
> DBREINDEX on them. The DBCC command returns that the
> index "is being rebuilt" and then moves on to the next
> one. Is there anywhere I can query to see when the index
> is actually finished being rebuilt? I'd like to know this
> so I can then run an UPDATE STATISTICS on it. Right now
> the procedure dies occasionally because it attempts to do
> the stats update before the other process is complete.
> I realize that I can schedule the stats update as a
> separate process later in the evening (my current
> workaround) but I was curious to see if there was another
> alternative. Thanks!
> -Dan

No comments:

Post a Comment