Index Rebuild

  • Hi All,

    I need to know when(date and time) the given index has been rebuild or reorganized or De

    fragmented?

    Please do the favor

  • Run the following, it will produce "Last_Updated"

    DBCC SHOW_STATISTICS ('TABLENAME',INDEXNAME );

    | If in Doubt...don't do it!! |

  • STATS_DATE() gives you the date on which the statistics for an index were update (update stats or alter index). Here is an example

    SELECT

    B.Name,A.Name as IndexName,

    STATS_DATE ( a.id , indid ) as IndexCreatedDate

    From sysindexes A, sysobjects B

    where a.id=b.id

    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @pradeepadiga

  • That info is not recorded anywhere automatically.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Then how can we get that info. Because i have to know which indexes need to be De fragmented ,

    any other ways?

  • Here is what mentioned in MSDN

    "STATS_DATE Returns the date of the most recent update for statistics on a table or indexed view."

    Read more on this here

    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @pradeepadiga

  • Thanks pradeep

  • you can not get that information from sql, however you should base your index rebuilds based upon the current level of fragmentation rather than use the last date of rebuild.

  • Agree with Steve. Re-indexing the tables based on the value of avg_fragmentation_in_percent column in the below query is the efficient way of rebuilding indexing in SQL Server 2005 and above.

    select * from sys.dm_db_index_physical_stats (db_id(), 0, null, 0, 'SAMPLED')

    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @pradeepadiga

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply