Duplicates for my reorg select scripts

  • One of my reorg process is select those high fragmentation index, but it gives me many duplicates, anyone could help me to fix it?

    SELECT

    DPS.index_id,

    QUOTENAME(I.name) Name,

    QUOTENAME(DB_NAME()) +'.'+ QUOTENAME(OBJECT_SCHEMA_NAME(I.[object_id])) + '.' + QUOTENAME(OBJECT_NAME(I.[object_id])) ObjectName,

    DPS.avg_fragmentation_in_percent,

    DPS.fragment_count,

    DPS.avg_fragment_size_in_pages,

    DPS.index_depth,

    FROM

    sys.dm_db_index_physical_stats (DB_ID(), NULL ,NULL, NULL, NULL) AS DPS

    INNER JOIN sys.indexes AS I

    ON DPS.[object_id]= I.[object_id]

    AND DPS.index_id = I.index_id

    INNER JOIN sysindexes AS SI with (NOLOCK)

    ON SI.id = DPS.object_id

    AND SI.indid = DPS.index_id

    WHERE

    DPS.avg_fragmentation_in_percent > 5 and DPS.index_id > 0

    and SI. rows > 100 and SI.rows <= 100000

    ORDER BY

    DPS.avg_fragmentation_in_percent DESC

  • It might be caused by partitions. I'm not sure what do you want to do with that.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I want to select any indexes which are higher than 5% for reorgs later

  • Is it the alloc_unit_type_desc (LOB Data) from dm_db_index_physical_stats causing your pain?

  • Can you provide more detail information?

  • Run sys.dm_db_index_physical_stats, is the "duplicate" due to LOB data?

  • Do you have any suggestions for me to overcome this issue?

  • Does this help?

    Avoiding never-ending index maintenance

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

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